[removed] Enter Key Press

前端 未结 3 1848
[愿得一人]
[愿得一人] 2021-01-14 15:00

Good Morning...

I am using java script in each page to trigger the Enter key press Event inside the textbox. It is working fine. Now i want to place the c

3条回答
  •  半阙折子戏
    2021-01-14 15:21

    You can use your id parameter instead of the ControlID, and when you use this function in your pages, you can pass the ControlID as a parameter:

    function EnterKeyPress(id,e) {
      if (window.event) { e = window.event; }
       if (e.keyCode == 13 || e.keyCode == 121) {
         document.getElementById(id).click();
       }
    }
    

    You are using ASP .NET, so in your code-behind you can assign the keypress event:

    TextBox1.Attributes.Add("onkeypress",
                          string.Format("EnterPressKey('{0}', event);", ibtnSubmit.ClientID));
    

    But wait, that functionality is already done on ASP .NET, you can use ASP:Panel controls to wrap your common controls, and you can assign a DefaultButton for the panel to indicate which button gets clicked when the Panel control has focus and the user presses the Enter key.

提交回复
热议问题