Reputation: 305
Is there a way to trigger a hidden button on an html markup page using jquery or jscript?
How would I do that if possible?
Thank you,
James
Upvotes: 4
Views: 3810
Reputation: 827218
With jQuery:
$('#buttonId').click();
or:
$('#buttonId').trigger('click');
With plain JavaScript:
document.getElementById('buttonId').onclick();
Since you're using ASP .NET you might want to get the button id by using the ClientID server-side property of the control:
$('#<%=Button.ClientID %>').click();
Or:
document.getElementById('<%=Button.ClientID %>').onclick();
Upvotes: 5
Reputation: 27561
If I understand correctly, you want to fire an event programmatically. This is usually not necessary. You can very easily move the button click even code to a new method, and have the event invoke that method. You can then also call the method in the code that would want to fire the button click even programmatically.
Upvotes: 0