Viewstate Issues

Viewstate Issues

Viewstate

  • Maintains the UI State of a web page
  • Used to preserve form information across postbacks
  • Enabled by default
  • Serializes the data in every control on the page regardless of whether it is actually used during a postback
  • Can be disabled for an application and enabled as needed on a page-by-page basis

Viewstate Behavior

  • The state of the controls is encoded and sent to the server with each form submission
  • The encoded Viewstate data is stored in a hidden field known as __VIEWSTATE
  • The server sends back the Viewstate data so that the controls render at their last state
  • The application can change the Viewstate data at the server
  • Use the Viewstate collection to modify the state of an individual control

Viewstate Issues

  • Viewstate is usually only needed on pages with forms, so can be disabled for most controls/pages
  • Disabling the Viewstate for a page or in web.config will still create the hidden view state variable when there is a form tag in the master page

Sources