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.
我所看到的是,在回发到页面之后,复选框以某种方式最终将其Checked属性设置为true,直到我到达Page_Load事件,我无法弄清楚为什么 - 我没有设置复选框的值或以任何方式修改复选框,此页面上没有转发器控件,当我提交表单时,肯定不会检查CheckBox。
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?
虽然页面本身非常复杂,但与CheckBox本身的交互完全是微不足道的 - 我已经花了很多时间试图弄清楚如何将此复选框的Checked值设置为true,但没有成功 - 调试/ diagnostics是否可以找出为什么这个复选框的检查值发生了变化?
UPDATE: So I've now switched to using a HtmlInputCheckBox
control:
更新:所以我现在切换到使用HtmlInputCheckBox控件:
// 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).
完全相同的事情仍然发生 - 在OnInit()期间Checked是假的,但是当我检查Page_Load()时是真的。该邮箱肯定在回发时未选中,并且Request.Form [“TelephonyEnabledCheckBox”]为“0”(表示未选中)。
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 个解决方案
#1
1
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.
我的建议是建立一个只有复选框的简单页面,然后看看它的行为方式。这样你就可以绝对确定问题不是由与页面上其他内容的奇怪交互引起的。
#1
1
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.
我的建议是建立一个只有复选框的简单页面,然后看看它的行为方式。这样你就可以绝对确定问题不是由与页面上其他内容的奇怪交互引起的。