2016-04-16 193 views
3

我正在使用複選框控件並在CHeckChanged中獲取它的值。我得到了正確的值,但在IF條件下,它甚至爲檢查返回FALSE,爲什麼?爲什麼複選框返回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(); 
       }} 
+0

是否將autopostback複選框設置爲true? –

回答

2

爲什麼你使用CheckBox chkOverAllApproval = sender as CheckBox; 要檢查同一複選框即chkOverAllApproval.Checked == true

所以,我認爲你應該刪除CheckBox chkOverAllApproval = sender as CheckBox;和運行代碼。