Easy solution for default button
There is a free component that allows you to assign a button to the “enter-pressed” client side event of input controls. If you type some text in textbox and press Enter, the form will postback, and the serverside click event of your button is fired. You don’t need to write any code, but you only need to use this control’s “DefaultButton” property. It you are a beginner programmer this could be a life saver. More about MetaBuilders DefaultButtons Control you can find at http://www.metabuilders.com/Tools/DefaultButtons.aspx
Default buttons in ASP.NET 2.0 and ASP.NET 3.5
ASP.NET 2.0 makes this problems easier and introduce a concept of a “default button”. New defaultbutton attribute can be used with <form> or <asp:panel> control. What button will be “clicked” depends of where actually cursor is and what button is chosen as a default button for form or a panel.
Here is sample HTML code that contains one form and one panel control:
<form defaultbutton=”button1″ runat=”server”>
<asp:textbox id=”textbox1″ runat=”server”/>
<asp:textbox id=”textbox2″ runat=”server”/>
<asp:button id=”button1″ text=”Button1″ runat=”server”/>
<asp:panel defaultbutton=”button2″ runat=”server”>
<asp:textbox id=”textbox3″ runat=”server”/>
<asp:button id=”button2″ runat=”server”/>
</asp:panel>
</form>
Enter Key in ASP.NET TextBox Control
2009. 5. 15. 18:10
반응형
반응형