Until recently, I had always used javascript to allow the enter key to submit a form (as seen in a previous posting called Submit Form On Enter Key Solution). Since then, I was queued into a GUImethod of controlling enter key form submissions in Visual Studio 2008 (and I’m sure this works in other versions as well).
To do this in the GUI style, click on the form of the page and then select the elements properties. Under the ASP.NET subheading, there is a form property called DefaultButton. Insert the button control id of the default button. This will essentially submit the form on enter (by performing the action on the specified button). The image to the left is an example of the form property section with a default button set to btnSetCookie. Note that for one reason or another, intellisense is not enabled on this property and you will have to manually type in the button control id.
Of course, you are not constrained to doing this in the GUI style. To submit a form on enter programmatically, simply find the form and insert the keyword defaultbutton=”BUTTON_CONTROL_ID_HERE”. Below is an example of how the above example would look programmatically.
<form id="frmTestForm" runat="server" defaultbutton="btnSetCookie">
This entry was posted on Wednesday, July 16th, 2008 at 7:46 am and is filed under C#. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


[...] Form Submit On Enter in Visual Studio post for both the GUI and programmatic way to submit form using the enter [...]
July 16th, 2008 at 7:50 am