简体   繁体   中英

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. ie, 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.

At the end of javascript method put

return true;

statement.

It should work.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM