Understanding ASP.NET View State
Understanding ASP.NET View State
I did not have a good understanding about ViewState until, I read the above article. It was other thing that I did not get a chance to use ViewState.
I always thought that viewstate restores the textbox, checkbox and other server controls(which implement IPostBackHandlerInterface) values across postback.
But actually, the LoadPostData event restores the values of the controls across PostBacks. ViewState is used to persist changed information across postbacks.
For ex:
A page contains three controls :
label - text= "Message",
button -text/id="ChangeMessage"
button -text/id="NoChange".
The ChangeMessage button changes the value of the label in its click event to "NewMessage".
The NoChange button does not do anything.
With ViewState Enabled, if you click the ChangeMessage button and then NoChange button, the label will be displaying NewMessage.
But with ViewState disabled, you will see that the label will be just Message instead of NewMessage.
I did not have a good understanding about ViewState until, I read the above article. It was other thing that I did not get a chance to use ViewState.
I always thought that viewstate restores the textbox, checkbox and other server controls(which implement IPostBackHandlerInterface) values across postback.
But actually, the LoadPostData event restores the values of the controls across PostBacks. ViewState is used to persist changed information across postbacks.
For ex:
A page contains three controls :
label - text= "Message",
button -text/id="ChangeMessage"
button -text/id="NoChange".
The ChangeMessage button changes the value of the label in its click event to "NewMessage".
The NoChange button does not do anything.
With ViewState Enabled, if you click the ChangeMessage button and then NoChange button, the label will be displaying NewMessage.
But with ViewState disabled, you will see that the label will be just Message instead of NewMessage.
No comments:
Post a Comment