Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Capturing Enter Key

Reply
Thread Tools

Capturing Enter Key

 
 
Muriel
Guest
Posts: n/a
 
      12-29-2005
I'm developing a website using visual studio .NET

I have a login form with a couple of textboxes and a login button. What I
want to do is capture the Enter key so that when the user presses Enter, it
will click the submit button.

I have searched the Internet for hours now trying to find out how to do it,
but any methods that I have seen do not work.

Can anyone help me do that?
 
Reply With Quote
 
 
 
 
Paul Henderson
Guest
Posts: n/a
 
      12-29-2005
If your login button is just an <input type="submit" .../>, then I
would expect it to respond to enter automatically. If, however, you are
using ASP textbox controls, then problems seem to occur, particularly
on esoteric browsers. If you are using an asp:HtmlButton or
asp:HtmlInputButton, you could try using an asp:Button instead, as
that's more likely to work. If that doesn't help, I would try adding a
(client-side) onkeydown event that checks for character 13 (return),
and if it detects it, calls the form's submit method.

It'd be helpful if you could post the code for the page in question,
though [and perhaps say what are the sorts of methods that did not
work...].

 
Reply With Quote
 
 
 
 
Muriel
Guest
Posts: n/a
 
      12-29-2005
Never mind!!! I found a way using Javascript
 
Reply With Quote
 
Muriel
Guest
Posts: n/a
 
      12-29-2005
Well, there were too many things I had tried in order to capture the Enter
Key. In the end, I used this Javascript:

<SCRIPT>

if (document.layers)
document.captureEvents(Event.KEYDOWN);

document.onkeydown = function (evt)
{
var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) :
event.keyCode;

if (keyCode == 13)
{
document.Login1470.cmdSubmit.click();
return false;
}
else
return true;
};

</SCRIPT>

It works like a charm.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
capturing from text area Shft+Enter, Control+Enter, Alt+Enter and browser issue. HopfZ Javascript 0 08-28-2006 10:11 AM
Problem with capturing enter key in TextBox within UserControl marcus.mordenfeld@gmail.com ASP .Net Web Controls 0 08-02-2006 04:11 PM
Capturing Enter Key Alper OZGUR ASP .Net 0 02-14-2006 01:21 PM
Enter Key H*ll, control enter key submit button BrianDH ASP .Net Web Controls 3 01-12-2005 08:29 PM
Replace Tab Key to Return Key (Enter Key) from Web Forms? M P ASP General 1 08-06-2004 08:32 AM



Advertisments