Click here to Skip to main content
15,895,871 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I simply want a jQuery code that triggers Button2 when jQuery is past over it.

Enacting "btn2_click"

This does not work:
JavaScript
$("#<%= Button2.ClientID %>").trigger("click");


ASP.NET
<asp:Button ID="Button2" onclick="btn2_click" runat="server" />


What I have tried:

I have tried:$("#<%= Button2.ClientID %>").click();
Posted
Updated 14-Apr-17 4:03am
v2
Comments
Karthik_Mahalingam 14-Apr-17 4:15am    
getting any error in chrome console?
teledexterus 14-Apr-17 4:43am    
It just does not function.
Karthik_Mahalingam 14-Apr-17 4:53am    
run the code in console window and check
Sinisa Hajnal 14-Apr-17 7:26am    
Do you use ready handler? Maybe the button is not created at the moment the script runs?

1 solution

There is nothing wrong with the code, but if the js is not running on the ready event of the document then make sure it appears after the button on the page.

<asp:Button ID="Button2" onclick="btn2_click" runat="server" />

<script type="text/javascript">
    $("#<%= Button2.ClientID %>").trigger("click");
</script>


If it still "doesn't work" then the problem lies elsewhere with something you haven't shown and you'll need to do some debugging to find out what it isn't working.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900