Reputation: 53
i wanna to understand difference between viewsate["x"] and __viewstate in view source
ie
in view source page there is view state in hidden control like:
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="dO3F9exemRdHoXxGHr"/>
but in c# i can create viewstate like:
viewstate["x"]="Hi";
so what is the difference???
and the string "Hi" where it be saved ? in this hidden or where?
Upvotes: 2
Views: 107
Reputation: 18127
When a page is rendered, it serializes its view state into a base-64 encoded string using the LosFormatter class and (by default) stores it in a hidden form field. On postback, the hidden form field is retrieved and deserialized back into the view state's object representation, which is then used to restore the state of the controls in the control hierarchy.
That means yes it saved in this hidden field
, but it is encoded
. Read MSDN article for more information. This quote is from 6.PARSING THE VIEW STATE.
If you have any interest you can parse the ViewState and see his "real values". You can search for view state parser, after research I found this Website
Upvotes: 2
Reputation: 161811
When you set view state using ViewState["x"]
, it is stored in the hidden field __VIEWSTATE
. It is first encoded, however, so you won't see "Hi" in that hidden field.
Upvotes: 0
Reputation: 68440
ViewState is a storage method on server side that is persisted on client side. What you're seeing is the two faces of the same coin
You use it on server side doing something like this
Viewstate["x"]="Hi";
And when the response is sent to the client, the ViewState storage is serialized and sent to the client in the form of an input field
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="dO3F9exemRdHoXxGHr"/>
Upvotes: 0