views:

39

answers:

2

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.

+1  A: 

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);


}
Vyas
please look on my edited question . I tested what u told . But its not working
Shameer
@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 .
Vyas
@Shameer:pls look `edit` in answer
Vyas
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
@Shameer:yes and AutoPostBack property is true
Vyas
autopostback protperty of check box is true .but its not working for me :(
Shameer
how you changed check box.checked in codebehind pls add code.
Vyas
i already added the code in my question . cbSelect.Checked = !cbSelect.Checked; . I can see the changes in each post back after clicking the button
Shameer
@Shameer:please check the EDIT
Vyas
Now its working. :) . So without that line it not fire cbSelect_CheckedChanged event, right??
Shameer
@Shameer:correct
Vyas
Thank you Vyas .
Shameer
A: 

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.

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