0

I have a checkbox named cbSelct. In a botton_click event i wrote

cbSelect.Checked=true

is the above code in the code behind page causes for a cbSelected_CheckedChanged event?

I created a new website and place a checkbox named cbSelect and a button.

protected void cbSelect_CheckedChanged(object sender, EventArgs e)
{
    Response.Write("testMessage ");
}
protected void Button1_Click(object sender, EventArgs e)
{
    cbSelect.Checked = !cbSelect.Checked;
}

I put a break point inside cbSelect_CheckedChanged event. Now according to the answers i got below, i understand that , if i clicked button it should break on cbSelect_CheckedChanged function. But i think cbSelect_CheckedChanged event is not firing while clicking the button.

2 Answers 2

1

Its affect CheckedChanged event.Before that you must use/create that event.

EDIT

make the AutoPostBack property of checkbox to true

EDIT

protected void Button1_Click(object sender, EventArgs e)
{
    cbSelect.Checked = !cbSelect.Checked;
cbSelect_CheckedChanged(cbSelect,  e);


}
Sign up to request clarification or add additional context in comments.

8 Comments

please look on my edited question . I tested what u told . But its not working
@Shameer:First ensure cbSelect_CheckedChanged event is correct or not for that take property window of cbSelect , click events button and click on CheckedChanged in list .
thanks for reply .yeah . its correct . i cross checked it. i can debug while changing checkbox manually. My question is if i change the check box.checked in codebehind, is it still call cbSelect_CheckedChanged
@Shameer:yes and AutoPostBack property is true
autopostback protperty of check box is true .but its not working for me :(
|
0

Yes, it will cause the cbSelected_CheckedChanged event to be fired but only if you have defined a cbSelected_CheckedChanged event.

You can try it -

private void cbSelected_CheckedChanged (Object sender, EventArgs e) 
{
   //your code
}

Place a break point here and debug your code. You will find that the cbSelected_CheckedChanged event will be fired.

2 Comments

please look on my edited question . I tested what u told . But its not working
In that case, set the AutoPostBack property to true. Vyas got it right. It should work.

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.