theLearner
theLearner

Reputation: 361

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

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.

Upvotes: 2

Views: 3160

Answers (2)

Amit Kumar Singh
Amit Kumar Singh

Reputation: 4475

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

Upvotes: 1

Abhishek K. Upadhyay
Abhishek K. Upadhyay

Reputation: 1032

At the end of javascript method put

return true;

statement.

It should work.

Upvotes: 0

Related Questions