Changing View State Options

You can specify which option to use at an application level in your application’s Web.config file.  You can also override the application level choice for one or more pages by overriding the GetViewStateLocation() function at the page class.

To change view state options for an application, modify your application’s Web.config to define one of the following keys in the appSettings section.


     <!-- only use one of the following lines -->

     <add key="ViewStateLocation" value="Page" />

     <add key="ViewStateLocation" value="File" />

     <add key="ViewStateLocation" value="Cache" />

     <add key="ViewStateLocation" value="Session" />


Changing the Database View State

To change the database view state:

<add key="ViewStateLocation" value="Session" />






     sqlconnectionstring="data source=MySqlServer;

          user id=ASPState;





Overriding the View State Location for a Specific Page

To override the view state location for a specific page, add the following function to the page class:

Protected Overrides Function GetViewStateLocation() As ViewStateLocation

     ‘ Only use one of the following lines

     Return ViewStateLocation.Page

     Return ViewStateLocation.Cache

     Return ViewStateLocation.Session

     Return ViewStateLocation.File

End Function

Further Reading

ASP.NET Caching Overview: