views:

330

answers:

2

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)

+1  A: 

My advice would be to build a simple page with only the checkbox and then see how that behaves. That way you can be absolutely sure that the problem isn't caused by strange interactions with other things on the page.

ctford
Already done that: as expected this doesn't happen on an empty page. The problem definitely is caused by strange interactions, but I just can't see what.
Kragen
A: 

I'm having this exact same problem. Has there been any resolution?

Evert Nugent
I cant remember, but I don't think so (I think I would have posted here if there was)I think in the end I just Request.Form[] to find the checked state.
Kragen