Anybody suggest me how to fire hyperlink click event using jquery's trigger function?
ASPX:
<asp:LinkButton runat="server" ID="lnkClickMe" Text="Click Me" ></asp:LinkButton>
JQUERY:
$("#lnkClickMe").trigger('click');
$("#lnkClickMe").click(function(){
alert('clicked');
});
Your client side code is correct. The only caveat is that ASP.NET could mangle the id of the control and it might not be lnkClickMe
at runtime. You could use a class selector or use the ClientID server side method to get the actual id:
$('#<%= lnkClickMe.ClientID %>').click(function(){
alert('clicked');
});
$('#<%= lnkClickMe.ClientID %>').trigger('click');
In ASP.NET 4.0 you could configure predictable names by using the ClientIDMode
setting:
<system.web>
<pages clientIDMode="Predictable"></pages>
</system.web>