Perform Button click event when user press Enter key in Textbox

后端 未结 7 1269
情书的邮戳
情书的邮戳 2020-12-01 07:19


&         


        
相关标签:
7条回答
  • 2020-12-01 08:17

    In the aspx page load event, add an onkeypress to the box.

    this.TextBox1.Attributes.Add(
        "onkeypress", "button_click(this,'" + this.Button1.ClientID + "')");
    

    Then add this javascript to evaluate the key press, and if it is "enter," click the right button.

    <script>
        function button_click(objTextBox,objBtnID)
        {
            if(window.event.keyCode==13)
            {
                document.getElementById(objBtnID).focus();
                document.getElementById(objBtnID).click();
            }
        }
    </script>
    
    0 讨论(0)
提交回复
热议问题