Wednesday, February 2, 2011

Set the default button that is triggered when the user hits the enter key


This was a major pain point in ASP.NET 1.1 and required some JavaScript to be written to ensure that when the user hit the enter key that the appropriate button on the form triggered a "click" event on the server-side.  Fortunately, you can now use the HtmlForm control's DefaultButton property to set which button should be clicked when the user hits enter.  This property is also available on the Panel control in cases where different buttons should be triggered as a user moves into different Panels on a page.
<form id="frm" DefaultButton="btnSubmit" runat="server">
  ...
</form>

No comments :

Post a Comment