title: asp.net c# is checkbox checked?
body: <p>How do I determine if the checkbox is checked or not checked?
  Very perplexed why this is not working - it is so simple!</p>
  
  <p>On my web form:</p>
  
  <pre><code>&lt;asp:CheckBox ID="DraftCheckBox" runat="server" Text="Save as Draft?" /&gt;
  &lt;asp:Button ID="PublishButton" runat="server" Text="Save" CssClass="publish" /&gt;
  </code></pre>
  
  <p>Code behind which runs in the click event for my save button:</p>
  
  <pre><code> void PublishButton_Click(object sender, EventArgs e)
  {
      if (DraftCheckBox.Checked)
              {
                  newsItem.IsDraft = 1;
              }
  }
  </code></pre>
  
  <p>When debugging it never steps into the If statement when I have the checkbox checked in the browser. Ideas?!</p>
  
  <p><strong>I think there maybe some other code affecting this as follows...</strong></p>
  
  <p>In Page_load I have the following:</p>
  
  <pre><code>PublishButton.Click += new EventHandler(PublishButton_Click);
  
  if (newsItem.IsDraft == 1)
      {
          DraftCheckBox.Checked = true;
      }
      else
      {
          DraftCheckBox.Checked = false;
      }
  </code></pre>
  
  <p>newsItem is my data object and I need to set the checkbox checked status accordingly.
  When the save button is hit I need to update the IsDraft property based on the checked status of the checkbox:</p>
  
  <pre><code>void PublishButton_Click(object sender, EventArgs e)
  {
      if (IsValid)
      {
          newsItem.Title = TitleTextBox.Text.Trim();
          newsItem.Content = ContentTextBox.Text.Trim();
          if (DraftCheckBox.Checked)
          {
              newsItem.IsDraft = 1;
          }
          else
          {
              newsItem.IsDraft = 0;
          }
  
          dataContext.SubmitChanges();
      }
  }
  </code></pre>
  
  <p>So, isDraft = 1 should equal checkbox checked, otherwise checkbox should be un-checked. Currently, it is not showing this.</p>