Hitting the enter key

Discussion in 'ASP .Net' started by Andy G, Dec 27, 2004.

  1. Andy G

    Andy G Guest

    I have a login page w/ a few buttons on it. When the user types in their
    username and password and hits the "Enter" key the applications runs the on
    click event for another button on the page. I don't think tab control has
    much to do with this. I need it so whenever someone hits the enter key it
    needs to fire the "Login" button. The login button is defined as an HTML
    Input control and all the other button is an ASP button (I'm sure this has
    something to do with it)

    Thanks
    Andy G, Dec 27, 2004
    #1
    1. Advertising

  2. You can intercept the client side enter keypress event of the text box and
    then do what you want using javascript code.

    Here are a couple good articles on the subject:
    http://www.allasp.net/enterkey.aspx
    http://www.aspnetpro.com/features/2004/06/asp200406so_f/asp200406so_f.asp

    You could also try using this free control.
    http://www.metabuilders.com/tools/DefaultButtons.aspx

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://Steve.Orr.net


    "Andy G" <> wrote in message
    news:...
    >I have a login page w/ a few buttons on it. When the user types in their
    > username and password and hits the "Enter" key the applications runs the
    > on
    > click event for another button on the page. I don't think tab control has
    > much to do with this. I need it so whenever someone hits the enter key it
    > needs to fire the "Login" button. The login button is defined as an HTML
    > Input control and all the other button is an ASP button (I'm sure this has
    > something to do with it)
    >
    > Thanks
    >
    >
    Steve C. Orr [MVP, MCSD], Dec 27, 2004
    #2
    1. Advertising

  3. Hi,

    Here is how I do it:

    My <body> tag looks like this:

    <body MS_POSITIONING="FlowLayout" onkeypress="CheckSubmit();">

    Then my CheckSubmit() routine looks like this:

    <script language="javascript">
    function CheckSubmit() {
    if (event.keyCode == 13) {
    document.getElementById("btnLogin").focus();
    }
    }
    </script>

    Everytime a key is pressed it calls the CheckSubmit() routine. If the
    keycode is 13 (Enter), then it sets focus to the btnLogin control, which in
    turn gets fired by letting the event bubble. Remember to change btnLogin to
    whatever is the id of your button. Good luck! Ken.

    --
    Ken Dopierala Jr.
    For great ASP.Net web hosting try:
    http://www.webhost4life.com/default.asp?refid=Spinlight
    If you sign up under me and need help, email me.

    "Andy G" <> wrote in message
    news:...
    > I have a login page w/ a few buttons on it. When the user types in their
    > username and password and hits the "Enter" key the applications runs the

    on
    > click event for another button on the page. I don't think tab control has
    > much to do with this. I need it so whenever someone hits the enter key it
    > needs to fire the "Login" button. The login button is defined as an HTML
    > Input control and all the other button is an ASP button (I'm sure this has
    > something to do with it)
    >
    > Thanks
    >
    >
    Ken Dopierala Jr., Dec 28, 2004
    #3
  4. Andy G

    Andy G Guest

    WOW! That is how to reply to a post...to the point, quick fix. Myself and
    my clients would like to thank you Ken.



    "Ken Dopierala Jr." <> wrote in message
    news:...
    > Hi,
    >
    > Here is how I do it:
    >
    > My <body> tag looks like this:
    >
    > <body MS_POSITIONING="FlowLayout" onkeypress="CheckSubmit();">
    >
    > Then my CheckSubmit() routine looks like this:
    >
    > <script language="javascript">
    > function CheckSubmit() {
    > if (event.keyCode == 13) {
    > document.getElementById("btnLogin").focus();
    > }
    > }
    > </script>
    >
    > Everytime a key is pressed it calls the CheckSubmit() routine. If the
    > keycode is 13 (Enter), then it sets focus to the btnLogin control, which

    in
    > turn gets fired by letting the event bubble. Remember to change btnLogin

    to
    > whatever is the id of your button. Good luck! Ken.
    >
    > --
    > Ken Dopierala Jr.
    > For great ASP.Net web hosting try:
    > http://www.webhost4life.com/default.asp?refid=Spinlight
    > If you sign up under me and need help, email me.
    >
    > "Andy G" <> wrote in message
    > news:...
    > > I have a login page w/ a few buttons on it. When the user types in

    their
    > > username and password and hits the "Enter" key the applications runs the

    > on
    > > click event for another button on the page. I don't think tab control

    has
    > > much to do with this. I need it so whenever someone hits the enter key

    it
    > > needs to fire the "Login" button. The login button is defined as an

    HTML
    > > Input control and all the other button is an ASP button (I'm sure this

    has
    > > something to do with it)
    > >
    > > Thanks
    > >
    > >

    >
    >
    Andy G, Dec 28, 2004
    #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. PJ6

    hitting the "enter" key

    PJ6, Aug 24, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    448
    The EEEdiot
    Aug 25, 2005
  2. Sunfire
    Replies:
    2
    Views:
    1,057
    Sunfire
    Nov 6, 2007
  3. BrianDH

    Enter Key H*ll, control enter key submit button

    BrianDH, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    388
    Anders Matthiessen
    Jan 12, 2005
  4. M P
    Replies:
    1
    Views:
    464
  5. Megha Vishwanath
    Replies:
    3
    Views:
    700
    Megha Vishwanath
    Jul 20, 2004
Loading...

Share This Page