C# – asp.net c# is checkbox checked

asp.netc++

How do I determine if the checkbox is checked or not checked?
Very perplexed why this is not working – it is so simple!

On my web form:

<asp:CheckBox ID="DraftCheckBox" runat="server" Text="Save as Draft?" />
<asp:Button ID="PublishButton" runat="server" Text="Save" CssClass="publish" />

Code behind which runs in the click event for my save button:

 void PublishButton_Click(object sender, EventArgs e)
{
    if (DraftCheckBox.Checked)
            {
                newsItem.IsDraft = 1;
            }
}

When debugging it never steps into the If statement when I have the checkbox checked in the browser. Ideas?!

I think there maybe some other code affecting this as follows…

In Page_load I have the following:

PublishButton.Click += new EventHandler(PublishButton_Click);

if (newsItem.IsDraft == 1)
    {
        DraftCheckBox.Checked = true;
    }
    else
    {
        DraftCheckBox.Checked = false;
    }

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:

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();
    }
}

So, isDraft = 1 should equal checkbox checked, otherwise checkbox should be un-checked. Currently, it is not showing this.

Best Solution

Specify event for Button Click

<asp:Button ID="PublishButton" runat="server" Text="Save" onclick="PublishButton_Click" />
Related Question