You must Sign In to post a response.
  • Category: .NET

    How call button click event on textbox enter key press event ?

    Are you looking for a way to call button click event on textbox enter key then read this thread to know how to do it


    How can i use two different submit button on their respective textbox enter in single Form tag in
    My target is i have two tab on a web page and on both of two tab i have their submit button with their textbox. now when i enter value in textbox in second tab and hitting enter key then its calling first button click on server side.
    I tried with different form tag as well as call server side method through js function but still not working.
    please help me to resolve this issue.

  • #763453
    1. You can use UseSubmitBehavior=false for both buttons. Both buttons will not working if you hit the enter key.

    2. you can use the following javascript to avoid enter key press in the text boxes.

    $(':input', base).keypress(function(e) {
    var code = e.keyCode || e.which;
    if(code == 13)
    return false;

    By Nathan
    Direction is important than speed

  • #763456
    To Trigger Button Click event on Enter Key Press in ASP.Net, you can use different panel controls for both textboxes and set 'DefaultButton' property of panel control to button id and then with the help of 'ClientScript.RegisterStartupScript' method you can trigger key press event of desired button
    see below link

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #763458
    Thanks Nathan.
    I tried with your given way and it solve my purpose.

    anil jain,
    Software Developer,

  • #763472
    Hello Anil Jain,

    As per your forum category it is .NET. Which should be ASP.NET if you are looking for Web... .NET is for Windows.

    For windows code should be like this :

    private void TextBoxUN_KeyPress(object sender, KeyPressEventArgs e)

    private void ButtonLogin_Click(object sender, KeyPressEventArgs e)
    // Write your code here.

    Hope you understand.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • Sign In to post your comments