What is the life span for items in view state?

Yesterday I went to an interview where the group asked me this question.

+4
source share
2 answers

Elements stored in the viewing state are transferred to the client’s browser as HTML in a hidden control and are sent back to the server when the user sends from this page (details from the irreplaceable ViewState: everything you wanted to know ):

1) ASP.NET starts rendering the page. All objects in the current ViewState are serialized using a custom format that looks like this: t<1234567890;t<p<l<prpA;prpB;prpC;>;l<valA;valB;valC;>>;

2) This serialized data is encoded and written to a hidden HTML element in the form of an ASP.NET page, where it looks like this (simulated data): dDwxMjM0NTY3ODkwO3Q8cDxsPHBycEE7cHJw

3) At this moment, the elements are hidden in the client browser: you can say that they are "sleeping".

4) If the client sends the page, ASP.NET decodes and deserializes the view state data into objects again, and they "live" until the request is complete (or until they are written to another page).

+4
source

It exists until your current page exists. ViewState stores the values ​​of the controls for a specific page on the client during subsequent work. Then the user requests another page of the previous data page is no longer available.

+3
source

All Articles