tags:

views:

29

answers:

1

I have used a checkbox and a button in my demopage. In checkbox AutopostBack property is false and I have used a server side event checkbox_checkedchanged() on

<asp:CheckBox ID="CheckBox1" runat="server" 
        oncheckedchanged="CheckBox1_CheckedChanged" /><asp:Button ID="Button1" runat="server"
        Text="Button" />

codebehind

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
    Response.Write("checked");
} 


protected void Page_Load(object sender, EventArgs e)
{

} 

Now when I click the button(in debug mode )first it go to pageload and then CheckBox1_CheckedChanged event is fired .

I want the explanation.that instead of enabling viewstate why the checkbox event is firing ?

A: 

Making AutoPostback=False just defers the event. If it was true, then postback would have happened to fire the event. In your scenario, whenever form was posted back, check-box control saw that its state has been changed (from POST data) and raised CheckedChanged event.

Not sure why you are discussing view-state here. But even if view-state is disabled, you will see this behavior because there are two state bags for any control - ViewState and ControlState. ControlState carries critical control information that is deemed to be needed for its working and it cannot be disabled. So in this case, Checkbox's previous state would have been stored in the control state.

VinayC
can you give me some link where i can get more clear ideas on view state and control state because its really confuses me....
subodh
As such, only control author can access (and bother about) ControlState and its recommended to add only critical data into the control state. Here are few links1) http://www.pluralsight-training.net/community/blogs/fritz/archive/2004/07/01/472.aspx 2) http://msdn.microsoft.com/en-us/library/1whwt1k7.aspx 3)http://stackoverflow.com/questions/381369/asp-net-2-0-control-state-vs-viewstate
VinayC