为什么复选框返回false值?

时间:2016-04-16 07:14:18

标签: c# asp.net if-statement checkbox

我正在使用Checkbox控件并在CHeckChanged获取它的值。我得到正确的值,但在IF条件下,它返回FALSE甚至检查,为什么?

 protected void chkOverAllApproval_CheckedChanged(object sender, EventArgs e)
    {
        try
        {
            CheckBox chkOverAllApproval = sender as CheckBox; //True i.e. correct value

                if (chkOverAllApproval.Checked == true) //return false and jump to else even for TRUE, why ?
                {

                    mdlCertificate.Hide();
                }}

1 个答案:

答案 0 :(得分:2)

为什么使用CheckBox chkOverAllApproval = sender as CheckBox; 您正在检查相同的复选框,即chkOverAllApproval.Checked == true

所以,我认为你应该删除CheckBox chkOverAllApproval = sender as CheckBox;并运行代码。