title: Trigger JavaScript Confirm() from code behind
body: <p>I am working on a Asp.Net application, currently i am trying to trigger a JavaScript <code>Confirm()</code> popup from the code behind. I would like to popup without clicking any <code>button_click</code> event. </p>
  
  <pre><code>IF not blnResult then
  
  popup message with OK&amp; CANCEL
  
  IF OK THEN Exit Sub
  
  ELSE
  
  no display
  
  END IF 
  </code></pre>
  
  <p>I tried to do below things and it's not firing popup, please assist.</p>
  
  <p>1) Created a button in ASPX</p>
  
  <pre><code>&lt;asp:Button ID="btnConfirm" runat="server" Text="Delete-All" OnClick="btnConfirm_Click" OnClientClick="Confirm()"/&gt;
  </code></pre>
  
  <p>JavaScript function</p>
  
  <pre><code>&lt;script language="javascript" type = "text/javascript"&gt;
      function Confirm() {
          var confirm_value1 = document.createElement("INPUT");
          confirm_value1.type = "hidden";
          confirm_value1.name = "confirm_value";
          if (confirm("Do you want to delete all records?")) {
              confirm_value1.value = "Yes";
          } else {
              confirm_value1.value = "No";
          }
          document.forms[0].appendChild(confirm_value1);
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>Code behind,</p>
  
  <pre><code>Public function GetConfirmation()
  
  btnConfirm_Click(btnConfirm, EventArgs.Empty)
  
  End Sub
  </code></pre>
  
  <p>Above line isn't firing the popup for me.</p>