Trigger both 'onClick' and 'onClientClick' event on an ASP button from Javascript

2.7k Views Asked by At

I'm working on an existing code and came across a ASP button which has a onClick and onClientClick event on it.

I'm trying to generate a click event from an external Javascript file so that both the events are triggered.

I'm using the below line to achive it-

document.getElementById("ID_ReleaseUserAuthPending_okBtn").click();

But the OnClientClick event is being triggered as expected, but the onClick event isn't. i.e., The Javascript method is being processed, but the onClick() in the C# codebehind isn't.

Please help me out if there is any way where I can call the onClick event too.

Thanks in advance.

2

There are 2 best solutions below

1
Abhishek K. Upadhyay On

At the end of javascript method put

return true;

statement.

It should work.

0
Amit Kumar Singh On

From the client click function, from js, call __dopostback. That is underscore underscore do post back. You can google it for sample code. https://www.codeproject.com/articles/667531/dopostback-function