c# - Invoke Javascript method from code-behind based on a condition. -


this javascript method in .aspx file. want invoke method code-behind based on condition:

function confirmboxandhidemessage() {     //hidemessage();     var response = confirm("are sure?.");     if (response == true) {         document.getelementbyid("<%=chkvalidated.clientid%>").checked = true;         hidemessage();     }     else {         hidemessage();         return true;     } } 

the condition upon want invoke this:

        if (obj.fkvalidationstatusid.hasvalue && obj.fkvalidationstatusid.value.equals(1))         {             btnproceedaddnewrecords.attributes.add("onclick", "javascript:return confirmboxandhidemessage();");           }         else         {             btnproceedaddnewrecords.attributes.remove("onclick");         } 

this condition being exercised in method called in pageload event inside

if (!ispostback) { /* condition */ } 

it not working , guess way adding method in button attribute wrong. request that, kindly suggest way can invoke javascript method code-behind based on stated condition. if think approach flawed, please suggest alternatives. thanks.

use set/unset onclientclick

if (obj.fkvalidationstatusid.hasvalue && obj.fkvalidationstatusid.value.equals(1))   {      btnproceedaddnewrecords.onclientclick="return confirmboxandhidemessage();";     } else   {      btnproceedaddnewrecords.onclientclick="retun false;";   } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -