开发者

Asp.Net - Debugging why CheckBox has Checked = true after a postback

开发者 https://www.devze.com 2022-12-13 02:12 出处:网络
I have a fairly complex page containing a checkbox: // In the .aspx <asp:CheckBox id=\"MyCheckBox\" runat=\"server\" text=\"Testing\" />

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 uncheck开发者_JAVA百科ed 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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消