Introduction

How to enable ViewState for selected controls

ViewState usage by controls

image1.png

Two cases when you may want to disable ViewState

How to disable ViewState

Although ViewState is designed to automatically save page and control property values across round trips to the browser, you can also add your own data to ViewState.

Like the session state object, the ViewState object contains a collections of key/value pair that represent the items saved in ViewState. To access this object , you use the ViewState property of the page.

Comparison between Session, Cookies and ViewState

There are three concept for maintaining the state of the page on the srever i.e. Session, Cookies and ViewState. But there are some differences among them. The differences table of these concepts are shown below.

image2.png

Summary

So ViewState is used by controls to retain state across post-backs. It is not always necessary, depending on control usage. ViewState is stored as a base64-encoded string and it can be encrypted. ViewState has some drawback i.e. it makes a page heavy.

Some Helpful Resources