Solved

Recognize Enter Key Pressed from any Form Field

Posted on 2004-09-08
7
284 Views
Last Modified: 2008-01-12
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.

0
Comment
Question by:ankuratvb
  • 4
  • 2
7 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12006695
Here is a good tutorial on how to accomplish this:
http://www.allasp.net/enterkey.aspx

Regards,

Aeros
0
 
LVL 17

Accepted Solution

by:
AerosSaga earned 250 total points
ID: 12006748
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.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12006772
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Author Comment

by:ankuratvb
ID: 12008191
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.

0
 
LVL 9

Author Comment

by:ankuratvb
ID: 12014527
Hi,

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.
Thanx
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12015314
right on
0
 
LVL 1

Expert Comment

by:dingir
ID: 20646041
this problem appear on forms where there are only one input element
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question