title: How to get checked value of HTML Input Checkbox in Code Behind
body: <p>I am using a html input checkbox control in a modalpopup which runs a javascript function in the <code>onclick</code> event. Now my challenge is getting the value of the checked property of this control from code-behind to do some behavioral stuff. When I added the <code>runat="server"</code> property to it and wrote <code>chkIsPrivate.Attributes.Add("onclick", "toggleCheckbox()");</code> in the page_load, the javascript function would not fire. </p>
  
  <p>I have searched online for a solution but didn't get any. I'm hoping someone will help me out here.</p>
  
  <p>Please note that without the <code>runat="server"</code> and the line of code in page_load, the javascript function fires when the checkbox control is clicked. But I need to get the value of the checked property in the code-behind.</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;tr&gt;
        &lt;td align="right"&gt;Private Campaign:&lt;/td&gt;
        &lt;td align="left"&gt;
               &lt;input id="chkIsPrivate" type="checkbox" onclick="toggleCheckbox()" /&gt;
        &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr id="password_tr" style="display: none"&gt;
        &lt;td align="right"&gt;Password:&lt;/td&gt;
        &lt;td align="left"&gt;
             &lt;asp:TextBox  ID="txtPassword" runat="server" TextMode="Password" Width="150px"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
        &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr id="confirmPassword_tr" style="display: none"&gt;
        &lt;td align="right"&gt;Confirm Password:&lt;/td&gt;
        &lt;td align="left"&gt;
          &lt;asp:TextBox ID="txtConfirmPassword" runat="server" TextMode="Password" Width="150px"&gt;&lt;/asp:TextBox&gt;
        &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>JavaScript:</p>
  
  <pre><code>function toggleCheckbox() {
                  var checkBox = document.getElementById("chkIsPrivate");
                  var pwd = document.getElementById("password_tr");
                  var confirmPwd = document.getElementById("confirmPassword_tr");
                  var hiddenVal = document.getElementById("privateHiddenInput");
                  if (checkBox.checked) {
                      pwd.style.display = "table-row";
                      confirmPwd.style.display = "table-row"; 
  
                  }
                  else {
                      pwd.style.display = "none";
                      confirmPwd.style.display = "none";
                  }
              }
  </code></pre>