When filling out a form on a web page you have probably experienced the fact that if you hit enter when typing in a single-line textbox the form is
submitted. This is a feature that browsers provide to make it possible to submit a form without having to touch the mouse. For example, when visiting
Google's homepage focus is immediately set to the search textbox and, after typing in your query, you can hit Enter to submit the form and see the results.
Since it is the browser that submits the form when the Enter key is pressed, you might think that as an ASP.NET developer you do not have to worry
about this functionality. Just create a Web Form, like always, and the user can optionally use the Enter key to submit the form. Unfortunately, the life
of an ASP.NET developer is never that simple! There are two cases where the user hitting Enter doesn't result in the desired behavior. The first case
involves a page with multiple Submit buttons. Hitting Enter has the effect of submitting the form using the first Submit button on the page, although
you may mean for a different button to have caused the submit (because you want its Click event handler to execute). The second case involves
hitting Enter in a form with only one form field when using Internet Explorer.
In this article we will examine these two cases in detail and look at simple workarounds. Read on to learn more!
Read More >