I have a fairly complex page containing a checkbox:
// In the .aspx
<asp:CheckBox id="MyCheckBox" runat="server" text="Testing" />
// In the .aspx.cs
protected System.Web.UI.WebControls.CheckBox MyCheckBox;
What I'm seeing is that after a postback to the page, the checkbox somehow ends up with its Checked property set to true by the time I reach the Page_Load
event, and I can't figure out why - at no point do I set the value of the checkbox or modify the checkbox in any way, there are no repeater controls, on this page and the CheckBox definitely isn't checked when I submit the form.
Although the page itself is pretty complex, the interaction with the CheckBox itself is completely trivial - I've already spent a lot of time trying to figure out how the Checked value of this checkbox is being set to true, with no success - what debug / diagnostics are there to figure out why this checkbox is having its checked value changed?
UPDATE: So I've now switched to using a HtmlInputCheckBox
control:
// In the .aspx
<input type="checkbox" id="TelephonyEnabledCheckBox" runat="server" />
// In the .aspx.cs
protected System.Web.UI.HtmlControls.HtmlInputCheckBox TelephonyEnabledCheckBox
The exact same thing still happens - during OnInit()
Checked is false, however by the time I get to Page_Load()
checked is true. The box is definitely unchecked on postback, and Request.Form["TelephonyEnabledCheckBox"]
is "0"
(indicating that it is not checked).
Whats going on? At the moment I'm worried that I'll need to resort to using the postback values directly (it would however be nice to understand whats going on)