What is ViewState? How is it encoded? Is it encrypted? Who uses ViewState?

Technology CommunityCategory: ASP.NETWhat is ViewState? How is it encoded? Is it encrypted? Who uses ViewState?
VietMX Staff asked 3 years ago

View state is a kind of hash map (or at least you can think of it that way) that ASP.NET uses to store all the temporary information about a page – like what options are currently chosen in each select box, what values are there in each text box, which panel are open, etc. You can also use it to store any arbitrary information.

The entire map is serialized and encoded and kept in a hidden variable (__VIEWSTATE form field) that’s posted back to the server whenever you take any action on the page that requires a server round trip. This is how you can access the values on the controls from the server code. If you change any value in the server code, that change is made in the view state and sent back to the browser.

Just be careful about how much information you store in the view state, though… it can quickly become bloated and slow to transfer each time to the server and back.

It’s not encrypted at all. Just base encoded, which easily reversible.