The current property settings of an ASP.NET page and those of any ASP.NET server controls contained within the page. ASP.NET can detect when a form is requested for the first time versus when the form is posted (sent to the server), which allows you to program accordingly.
Using the @page directive and setting ‘EnableViewStateMac’ property to true.
You can look at the source for a page in your browser. In Internet Explorer, right click the page and select View Source. Within the source for your page, you can see the hidden field that contains the view state for a page, called_VIEWSTATE. If the view state hidden field is quite large, you might want to disable view state for the control.
In some cases, using view state is not feasible. The alternative for view state is session state. Session state is employed under the following situations:
Large amounts of data – View state tends tincrease the size of both the HTML page sent the browser and the size of form posted back. Hence session state is used.
Secure data – Though the view state data is encoded and may be encrypted, it is better and secure if nsensitive data is sent tthe client. Thus, session state is a more secure option.
Problems in serializing of objects intview state – View state is efficient for a small set of data. Other types like DataSet are slower and can generate a very large view state.
The view state can be encrypted by setting EnableViewStateMac to true and either modifying the <machineKey> element in Machine.config to <machineKey validation=”3DES” /> or by adding the above statement to Web.config.
No. Http is a stateless protocol. In order to maintain the state we need either of the following in the pages.
Query string or Request.Form
Maximum size of a viewstate should not be more than 25-30% of the page size.