Recognize Enter Key Pressed from any Form Field

I have a form with lots of textboxes and listboxes etc.

What i want is that whenever the user presses the enter key,be it from any of the form fields,it should recognize it and invoke the insert button click event which inserts the form data into a database.

Who is Participating?
AerosSagaConnect With a Mentor Commented:
another work around:
This has got to be the wierdest fix I've ever seen, but it works. I was completely puzzled as to why my search button would -not- work when I entered data and hit enter. It would just not do anything. Then I read this article on Matt Berther's blog:

For the last few hours, I've been trying to figure out why my event handler is not being hooked up when I hit the ENTER key to submit my ASP.NET form.

As it turns out, this is a bug with ASP.NET. If you're not aware of this, the work around is to insert an invisible *HTML* textbox (an asp:TextBox wont work).

Add this line somewhere on the page:
<input type="text" style="display:none">
, and all will work as expected.
Here is a good tutorial on how to accomplish this:


Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

ankuratvbAuthor Commented:
I'll be going thru the links and trying the fix as well.

In my case,while entering data,only the insert and the cancel buttons are enabled.On pressing enter,the focus goes to the cancel button and its click event generated.

ankuratvbAuthor Commented:

After using the text box fix,what happens is that on pressing enter,control goes to the next(in sequence according to the html) submit button(asp:Button's are submit buttons) on the page.

SO i just had to change the html so that the insert button happens to be the next button in the html.

And it works fine now.
right on
this problem appear on forms where there are only one input element
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.