August 18 2008

Setting Default Button when Hitting <Enter> in a Text Box

The Problem:

You’re in a text box, and when you hit the <Enter> key, some random button is clicked instead of the button just below your set of text boxes.

The Fix:

Surround your text boxes and button with an <asp:panel> and set the panel property DefaultButton to the ID of the button you want to be clicked when the user hits <Enter>.  You can set this property in either HTML or from the code-behind.

The Caveat:

This requires the browser to have javascript enabled.  :(

Comments (View)
blog comments powered by Disqus

Please...

Leave a comment if this has helped or offended you.

StackOverflow Id