How do I fire a server side button click event from JavaScript?
I tried like this:
document.getElementById("<%= ButtonID.ClientID %>").click();
But no use. How can I do it?
Another option is to use the onclientclick event which allows you to run a JS function w/o a server interaction. In the first button (adds a new row to the table), I have a server side onclick="btnAdd_Click" as well as a client side OnClientClick="javascript:ResetSaveFlag()" .
private void SubGraphButton_Click(object sender, RoutedEventArgs args) { } private void ChildNode_Click(object sender, RoutedEventArgs args) { // call SubGraphButton-Click(). }
Use the OnClientClick property to specify additional client-side script that executes when a Button control's Click event is raised. The script that you specify for this property is rendered in the Button control's OnClick attribute in addition to the control's predefined client-side script.
You can just place this line in a JavaScript function:
__doPostBack('btnSubmit','OnClick');
Or do something like this:
$('#btnSubmit').trigger('click');
var clickButton = document.getElementById("<%= btnClearSession.ClientID %>"); clickButton.click();
That solution works for me, but remember it wont work if your asp button has
Visible="False"
To hide button that should be triggered with that script you should hide it with <div hidden></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With