I was working on an internal web site today and I needed to allow the user to enter some information into a asp:TextBox control and press enter to submit the form.
It looks something like this:
I’ve done this in the past and decided to do a quick Google to find out how to do it again (it would have been great if I remembered how to do it). I figured searching Google was faster than searching my code.
It is simple and here is what I consider the easiest way to click a button when a user presses enter while in a TextBox control. Wrap the TextBox and Button (or ImageButton) in a asp:Panel and set the Panel’s DefaultButton property. If you don’t want the ImageButton to show up, set the Height and Width to “0px”.
Leave a comment if you want sample code.