Fire event ASP.NET TextBox for input click

How do I fire an ASP.NET click event when a user presses an enter key.

This is what I am doing now, but it does not work:

function KeyDownHandler(event) {
    if (event.keyCode == 13) {
        __doPostBack('<% ButtonGetListforUser.ClientID %>', 'OnClick');
        isClicked = true;
    }
}
+3
source share
4 answers

Try using the Panel.DefaultButton property

+10
source

I used this example to make it work Property.DefaultButton Exsample

+2
source
$(document).ready(function(){ 
   $(window).keydown(function(e){
      if(e.keyCode == 13) $('#<% ButtonGetListforUser.ClientID %>'.click();
   }); 
});
-1

# ASPNET
: 1

  • Add a TextChanged event to the text field, and then add code to this block as shown below.

    protected void Textbox1_TextChanged(object sender, EventArgs e)
    {
        // Add your code here
    }
    
  • Add a block below to add Enter to the text box

    private void Textbox1_Enter(object sender, System.EventArgs e)
    {
        Textbox1_TextChanged((object)sender, (EventArgs)e);
    }
    
-3
source

Source: https://habr.com/ru/post/1776409/


All Articles