When developing the desktop application it is very common that you set the default accept and cancel button for the window form. So that if user click the enter key then action take place like submission of the inputs entered by the user or other actions and when user click the esc key then the form close. In window form , form has two properties called accept button and cancel button which are used for this purpose. But when you want to give this type of functionality in the web application then there is little difference and more ways that you can give this functionality. In this post I will show you how you can give this functionality to user.
With the release of the ASP.NET 2.0, the problem of making the default button is much easier with the introduction of the "default button" property of the form. Now 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:
the value of the keycode, if 13 which is used as the enter key value, it will call the click event of the button which is set as the default button and return false else it will return true.
All and any comments / bugs / suggestions are welcomed!