4

In Webforms I have a CheckBox and Button.

<asp:CheckBox ID="checkBox" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Check" OnClick="Button1_Click"/>

I want to handle Checkbox's check status with ButtonClick. But it is only getting false value.

if (checkBox.Checked == (true))
{
    Label1.Text = "Selected";
}
else
{
    Label1.Text = "Not Selected";
}

After every click I am getting Not Selected in my Label. I think this is so basic but now I couldn't fix.

Is there anyway to fix this.

6
  • try checkbox.value Commented Aug 8, 2017 at 12:25
  • in Webforms it is not possible Commented Aug 8, 2017 at 12:26
  • Please show us the whole method that contains the if (checkBox.Checked == ... part (or at least its full name and declaration). Commented Aug 8, 2017 at 12:33
  • Maybe it needs DataBound before the checking its value. Commented Aug 8, 2017 at 12:39
  • I tried its working perfectly fine.... recheck for minute mistakes Commented Aug 8, 2017 at 13:48

1 Answer 1

5

Not sure if this has been solved, this is beacause Autopostback is not enabled. Change it to below

    asp:CheckBox ID="checkBox" AutoPostBack=“true” runat="server"  ```
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.