What is ViewState and how do it work?

I am not the author of the article, but if you really want to understand ViewState, you should read it.It is still a very good read, but it is a bit dated.

A view state is a kind of map that is used to store temporary information about a page, like what options are currently chosen in each box, what values are in the text box and which panel are open.You can use it to store arbitrary information.

Whenever you take any action on the page that requires a server round trip, the map is kept in a hidden variable and posted back to the server.The values on the controls can be accessed from the server code.If you change any value in the server code, that change is sent back to the browser.

If you store too much information in the view state it can quickly become bloated and take too long to transfer to the server and back.

I don't know how strong it is, but it's not easy to read.I wouldn't use it for sensitive information.In the comments, it was pointed out that it's not secure.It is base encoded, which is easy to change.

Information about all the controls on the page can be found in a hidden field.The view state should never contain sensitive information.The machineKey> element's validation attribute should be set in the machine.config file.An article on MSDN describes ViewState.

Microsoft® ASP.NET view state is a technique used to persist changes to the state of a Web Form across postbacks.

View State stores the value of page controls as a string which is hashed and encoded.Information about page and its controls is what it contains.

ViewState isn't Encrypted by default.The below code is used to run the previous input type value.

The output for the above code will be User Name.Is it possible that b??+)?f

You would come up with the cost of viewstate if you read the details of the article.

On all page visits, the Page class gathers the collective view state for all of the controls in its control hierarchy and serializes the state to a base-64 string.This is the string that is hidden in the form.On postbacks, the load view state stage needs to update the controls in the control hierarchy.

ViewState is not used as a default.If your page has an action with controls, you may want to use viewstate.

Asp.net uses ViewState to enable the postback model.The state for all controls is stored in this string.