checkbox - asp.net
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,开发者_Go百科 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.
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);
}
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.
精彩评论