tags:

views:

35

answers:

2

Suppose there is CheckBox and I want to perform checkBox_CheckedChanged event when it is checked.how to do that?

A: 

Try setting the AutoPostBack property to true.

Darin Dimitrov
What is the resion to make autoPostBack=true;Ya its working now but why its not working when autopostback =false;
Shalni
A: 

Markup:

<asp:CheckBox runat="server" AutoPostBack="true" OnCheckedChanged="checkBox_CheckedChanged" />

Code-behind:

using System.Web.UI.WebControls;

protected void checkBox_CheckedChanged(object sender, EventArgs e)
{
    CheckBox checkBox = (CheckBox)sender;
    bool @checked = checkBox.Checked;
    // do other stuff
}
abatishchev
it is not working sir.
Shalni
will you give some new code?
Shalni
@Shalni: What exactly doesn't work?
abatishchev
sir,If i write bool @checked = checkBox.Checked; then error comes that checked is keyword identifier expected. This error come? So That code is not working
Shalni
@Shalni: I guess that `bool checked` doesn't work because of syntax keyword but `bool @checked` where escaping took place - should work properly. Does it?
abatishchev
bool @checked is fine but checkBox.Checked is giving error.But I remove that error by using if condition.
Shalni
@Shalni: I edited my post - now everything works properly.
abatishchev