Correct Click Event on Typing Enter

If you work with ASP.Net and have multiple buttons on the form that correspond to different textboxes you’ve probably run into the problem of a user pressing the “Enter” key and submitting to the wrong button’s server “Click” event.

I finally found the solution @ http://forums.asp.net/p/1292662/2501472.aspx using Panel and DefaultButton.

You can put TextBox and Button inside the Panel and use DefaultButton property. In that case you will not need any javascript:

<asp:Panel ID="Panel1" runat="server" DefaultButton="Button1">

Comments are closed.