title: Invoke Javascript method from code-behind based on a condition.
body: <p>This is my javascript method in .aspx file. I want to invoke this method from code-behind based on a certain condition:</p>
  
  <pre><code>function confirmboxAndHideMessage() {
      //HideMessage();
      var response = confirm("are you sure?.");
      if (response == true) {
          document.getElementById("&lt;%=chkValidated.ClientID%&gt;").checked = true;
          HideMessage();
      }
      else {
          HideMessage();
          return true;
      }
  }
  </code></pre>
  
  <p>The condition upon which I want to invoke is something like this:</p>
  
  <pre><code>        if (obj.fkValidationStatusId.HasValue &amp;&amp; obj.fkValidationStatusId.Value.Equals(1))
          {
              btnProceedAddNewRecords.Attributes.Add("OnClick", "javascript:return confirmboxAndHideMessage();");  
          }
          else
          {
              btnProceedAddNewRecords.Attributes.Remove("OnClick");
          }
  </code></pre>
  
  <p>This condition is being exercised in a method which is called in PageLoad event inside </p>
  
  <pre><code>if (!IsPostBack) { /* condition */ }
  </code></pre>
  
  <p>It is not working and my guess is that the way i am adding the method in button attribute is wrong. My request is that, kindly suggest a way I can invoke this javascript method from my code-behind based on the stated condition. If you think that my approach is flawed, Please do suggest Alternatives. Thanks.</p>