Tip Details Add a Related Tip

Rate as: Positive Negative

Setting the button triggered by the enter key

In ASP.Net 2.0, you can actually set the button that will be triggered in a form when the user presses the Enter key. This is a nice improvement over ASP.Net 1.1.

The HtmlForm control has a DefaultButton property which allows you to set which button is effectively clicked when the user hits Enter. This property is also available on the Panel control in cases where you want different buttons to be triggered when a user moves into different Panels on the page.

It's pretty easy to use this as this code example shows:

<form id="formId" DefaultButton="btnNum3" runat="server">
   ...

   <input type="submit" name="btnNum1" id="btnNum1" value="Button 1" />
   <input type="submit" name="btnNum2" id="btnNum1" value="Button 2" />
   <input type="submit" name="btnNum3" id="btnNum1" value="Button 3" />
</form>

In this example, even though there are two other submit buttons declared before it in the form, btnNum3 will be the button that is pushed if the user hits Enter.
Rating: 100% positive, 1 Vote
Categories: programming ASP .Net web
Added: on Jun 05, 2007 at 6:09 pm
Added By: an anonymous user

Comments on this Tip

Add a Comment
There are no comments for this tip
Your Comment:
(how to format)
Rate This Tip:

Verify Humanity:
Sorry, we know it's annoying, but please enter the characters shown in the image to the left so that we know you're an actual person and not an evil spammer. Thanks.
       

Related Tips

Electronic payment processing in ASP.Net web applications

Categories: programming ASP .Net web
100% positive, 1 comment - last added on Apr 30, 2007 at 1:32 pm
– Tip added by an anonymous user on Apr 25, 2007 at 12:01 pm

Adding an email attachment in .Net

Categories: programming ASP .Net web
0% positive, 0 comments
– Tip added by an anonymous user on Apr 26, 2007 at 3:49 pm

Using ASP.Net variables in your Javascript code

100% positive, 2 comments - last added on Sep 04, 2007 at 7:12 am
– Tip added by an anonymous user on May 05, 2007 at 7:00 am

Hex colors in System.Drawing

Categories: ASP .Net web
100% positive, 1 comment - last added on May 27, 2007 at 8:18 pm
– Tip added by an anonymous user on May 25, 2007 at 8:44 am

Master pages in ASP.Net 2.0

Categories: programming ASP .Net
100% positive, 0 comments
– Tip added by an anonymous user on Apr 24, 2007 at 3:05 pm

Maintaining page scroll position with ASP.Net 2.0

Categories: ASP .Net programming
no ratings, 0 comments
– Tip added by an anonymous user on Jun 08, 2007 at 12:31 pm

Telling when an iframe is done loading

100% positive, 1 comment - last added on Sep 07, 2008 at 10:57 pm
– Tip added by an anonymous user on Apr 18, 2008 at 8:05 am

Using functions in conditionals in Smarty

Categories: php programming Smarty web
100% positive, 3 comments - last added on May 21, 2008 at 1:36 pm
– Tip added by rlansky on Aug 10, 2007 at 1:02 pm

Something to consider before switching platforms

100% positive, 0 comments
– Tip added by an anonymous user on Sep 25, 2007 at 7:31 pm

Random number generation

100% positive, 0 comments
– Tip added by an anonymous user on Aug 05, 2008 at 6:49 am

Optional parameters in javascript functions

100% positive, 0 comments
– Tip added by an anonymous user on Jul 30, 2008 at 10:44 am

Detecting if a variable exists in Javascript

100% positive, 1 comment - last added on Sep 03, 2008 at 6:12 am
– Tip added by an anonymous user on Jul 22, 2008 at 8:31 am

Redirecting in PHP

100% positive, 0 comments
– Tip added by an anonymous user on Jul 17, 2008 at 7:27 am

compressing javascript

100% positive, 0 comments
– Tip added by an anonymous user on Jun 12, 2008 at 3:02 pm

Copyright date on sites

Categories: web programming php Smarty
100% positive, 0 comments
– Tip added by an anonymous user on Mar 11, 2008 at 8:14 am

Javascript variable naming

100% positive, 1 comment - last added on Jul 22, 2008 at 8:33 am
– Tip added by an anonymous user on Sep 30, 2007 at 7:28 am

Avoiding facebook timeout errors

Categories: Facebook programming web
100% positive, 0 comments
– Tip added by an anonymous user on Aug 21, 2007 at 5:21 pm

attaching events to nodes in Javascript

no ratings, 0 comments
– Tip added by an anonymous user on Aug 18, 2008 at 11:23 am

animating elements with jQuery

no ratings, 0 comments
– Tip added by an anonymous user on Aug 04, 2008 at 1:46 pm

Code for creating Javascript CSS charts

no ratings, 0 comments
– Tip added by an anonymous user on Aug 21, 2007 at 12:23 pm