Return to Snippet

Revision: 58066
at June 23, 2012 01:30 by weldonr30


Initial Code
$("#<%=txtPassword.ClientID %>").keydown(function(event) {

      if (event.keyCode == 13) {

          eval($("#<%=btnLogin.ClientID %>").attr('href'));

     }

  });

Initial URL
http://www.mitchelsellers.com/blogs/2012/06/21/jquery-and-clicking-an-aspnet-linkbutton.aspx

Initial Description
This is a pretty standard jQuery method to listen for the enter key and simply "click" the button.  However, if you are using a LinkButton this code will not work.  The reason for this is that a LinkButton is rendered to the browser as an Anchor tag with a href property that contains a javascript action to trigger the postback.  Click does nothing on the button as there is nothing for it to complete.

Initial Title
jQuery and Clicking an ASP.NET Linkbutton

Initial Tags
jquery, aspnet

Initial Language
jQuery