jQuery and Clicking an ASP.NET Linkbutton


/ Published in: jQuery
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. $("#<%=txtPassword.ClientID %>").keydown(function(event) {
  2.  
  3. if (event.keyCode == 13) {
  4.  
  5. eval($("#<%=btnLogin.ClientID %>").attr('href'));
  6.  
  7. }
  8.  
  9. });

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.