Capturing Enter Key

Discussion in 'ASP .Net' started by Muriel, Dec 29, 2005.

  1. Muriel

    Muriel Guest

    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?
     
    Muriel, Dec 29, 2005
    #1
    1. Advertising

  2. 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...].
     
    Paul Henderson, Dec 29, 2005
    #2
    1. Advertising

  3. Muriel

    Muriel Guest

    Never mind!!! I found a way using Javascript
     
    Muriel, Dec 29, 2005
    #3
  4. Muriel

    Muriel Guest

    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.
     
    Muriel, Dec 29, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alper OZGUR

    Capturing Enter Key

    Alper OZGUR, Feb 14, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    404
    Alper OZGUR
    Feb 14, 2006
  2. BrianDH

    Enter Key H*ll, control enter key submit button

    BrianDH, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    446
    Anders Matthiessen
    Jan 12, 2005
  3. Replies:
    0
    Views:
    243
  4. M P
    Replies:
    1
    Views:
    556
  5. HopfZ
    Replies:
    0
    Views:
    629
    HopfZ
    Aug 28, 2006
Loading...

Share This Page