Professional Web Applications Themes

Textbox, button and Enter on keyboard - ASP.NET General

Question (using C# and ASP.NET), I have a textbox and a buttonClick on my asp.net page. I would like be able to hit the Enter button on the keyboard and have it do the same thing as the buttonClick. In other words how do you get Enter button on the key board to perform the same operation as a button click event. Any help would be great, Thanks D....

  1. #1

    Default Textbox, button and Enter on keyboard

    Question (using C# and ASP.NET),

    I have a textbox and a buttonClick on my asp.net page. I would
    like be able to hit the Enter button on the keyboard and have it do the
    same thing as the buttonClick. In other words how do you get Enter button
    on the key board to perform the same operation as a button click event.

    Any help would be great,
    Thanks

    D.


    DDK Guest

  2. #2

    Default Re: Textbox, button and Enter on keyboard

    You can intercept the client side enter keypress event of the text box and
    then click
    the correct button using javascript code.
    Here's a good example:
    [url]http://www.kamp-hansen.dk/pages/showdoc.asp?id=28&menuid=21&menuid=18[/url]

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

    --
    I hope this helps,
    Steve C. Orr, MCSD
    [url]http://Steve.Orr.net[/url]


    "DDK" <ddkennardhotmail.com> wrote in message
    news:OFDJbyzSDHA.1684TK2MSFTNGP11.phx.gbl...
    > Question (using C# and ASP.NET),
    >
    > I have a textbox and a buttonClick on my asp.net page. I would
    > like be able to hit the Enter button on the keyboard and have it do the
    > same thing as the buttonClick. In other words how do you get Enter button
    > on the key board to perform the same operation as a button click event.
    >
    > Any help would be great,
    > Thanks
    >
    > D.
    >
    >

    Steve C. Orr, MCSD Guest

  3. #3

    Default Re: Textbox, button and Enter on keyboard

    Hi

    Basic example... simply say what submitbutton should be clicked onkeydown
    event
    I think this will work in netscape also but havent tested it....

    <html>
    <head>
    <SCRIPT>
    function submitOnEnter(submitBtn) {
    var keyCode = doent.all ? event.keyCode :evt.which ? evt.which :
    evt.keyCode ? evt.keyCode : evt.charcode;
    if (keyCode == 13) submitBnt.click();
    }
    </script>
    </head>
    <body>
    <form >
    <input type="text" name="myField"
    onkeydown="submitOnEnter(this.form.submitBtn1)">
    <input type="submit" name="submitBtn1" value="submit1">
    <input type="text" name="myField"
    onkeydown="submitOnEnter(this.form.submitBtn2)">
    <input type="submit" name="submitBtn2" value="submit2">
    </form>
    </body>
    </html>

    So if sumbitOnEnter-script is registered and you want to set some field to
    use it
    myInput.Attributes.Add("onkeydown","submitOnEnter( this.form." + BUTTONNAME +
    ")");
    Where BUTTONNAME is the button (surprise ;) ) to click

    --
    Best Regards
    Vidar Petursson
    ==============================
    Microsoft Internet Client & Controls MVP
    ==============================
    "DDK" <ddkennardhotmail.com> wrote in message
    news:OFDJbyzSDHA.1684TK2MSFTNGP11.phx.gbl...
    > Question (using C# and ASP.NET),
    >
    > I have a textbox and a buttonClick on my asp.net page. I would
    > like be able to hit the Enter button on the keyboard and have it do the
    > same thing as the buttonClick. In other words how do you get Enter button
    > on the key board to perform the same operation as a button click event.
    >
    > Any help would be great,
    > Thanks
    >
    > D.
    >
    >

    Vidar Petursson Guest

Similar Threads

  1. Default Button to Catch <ENTER> key
    By JP in forum ASP.NET General
    Replies: 2
    Last Post: July 25th, 01:45 PM
  2. Textbox and button -- enter key/submit - REFERENCE
    By KathyB in forum ASP.NET General
    Replies: 0
    Last Post: July 24th, 10:24 PM
  3. Q: Textbox press Enter submit form (ASCX version)
    By w. jORDAN in forum ASP.NET General
    Replies: 3
    Last Post: July 22nd, 02:41 AM
  4. Get text in TextBox without pressing Enter key
    By mg in forum ASP.NET General
    Replies: 5
    Last Post: July 14th, 02:09 PM
  5. Replies: 0
    Last Post: June 30th, 05:39 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139