1.0 / 1.1: Enter key for multiple forms

In 1.0 and 1.1, there seems to be no easy way of having multiple forms on a webpage that each perform separate actions when you press the enter button from within them (instead of clicking a button to postback to the server). If you press enter anywhere, the click event for the first button added to the form is run. In standard html, this would easily be accomplished by having two separate forms, however you cannot have two separate forms in

Note that this is solved by dividing the form up with panels and specifying the defaultbutton attribute for each panel in .net 2.0

To solve this, I added some js to the onkeydown event on my textbox on my second form. Note that this works with both firefox and i.e. (hence event.which and event.keyCode).

myTextBox.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('"+ myButton.UniqueID + "').click();return false;} } else {return true}; ");

Some related articles are as follows:,guid,dfa0280f-a20e-4c47-8b39-bf7cb83e3849.aspx

You May Also Like

About the Author: rnowik

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.