3

How do i fire a ASP.NET click event when the user press enter.

This is what i do now but it does not work:

function KeyDownHandler(event) {
    if (event.keyCode == 13) {
        __doPostBack('<% ButtonGetListforUser.ClientID %>', 'OnClick');
        isClicked = true;
    }
}
abatishchev
  • 98,240
  • 88
  • 296
  • 433
Kimtho6
  • 6,154
  • 9
  • 40
  • 56

4 Answers4

10

Try to use the Panel.DefaultButton Property

Oleg Kalenchuk
  • 517
  • 1
  • 5
  • 12
  • This worked for me. Wrap your textbox and button in a Panel control and set the DefaultButton to the id of the button control. – Ian Houghton May 02 '13 at 09:27
2

i used this exsample to make it work Panel.DefaultButton Property Exsample

Kimtho6
  • 6,154
  • 9
  • 40
  • 56
-1
$(document).ready(function(){ 
   $(window).keydown(function(e){
      if(e.keyCode == 13) $('#<% ButtonGetListforUser.ClientID %>'.click();
   }); 
});
rbhro
  • 218
  • 1
  • 4
  • give some Explanation please. obviously this is JavaScript but you could mention that you went with a JavaScript approach and why. – Malachi Mar 04 '14 at 20:09
-3

This answer for C# ASPNET
Control name : Textbox1

  • Add TextChanged event for the textbox then add your code in this block as below.

    protected void Textbox1_TextChanged(object sender, EventArgs e)
    {
        // Add your code here
    }
    
  • Add below block to add Enter event to textbox

    private void Textbox1_Enter(object sender, System.EventArgs e)
    {
        Textbox1_TextChanged((object)sender, (EventArgs)e);
    }
    
Aliaksei Kliuchnikau
  • 13,589
  • 4
  • 59
  • 72
Salih
  • 1