开发者

where the asp:controls values are stored if enableviewstate is disabled?

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, EventAr开发者_高级运维gs 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 ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜