---
title: "EnableViewState in ASP.Net"  
description: "The ASP.NET view state is the technique used by an ASP.NET Web page to persist changes to the state of a Web Form across postbacks. The view state of"  
author: "Sumit Kesarwani"  
published: 2013-05-10  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/500/enableviewstate-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# EnableViewState in ASP.Net

The ASP.NET view state is the technique used by an ASP.NET [Web page](https://www.mindstick.com/forum/718/sql-server-report-alignment-to-center-of-web-page) to persist changes to the state of a Web Form across postbacks. The view state of a page is, by default, placed in a hidden [form field](https://www.mindstick.com/forum/158282/how-to-validate-a-form-field-using-jquery) named __VIEWSTATE. This hidden form field can easily get very large, on the order of tens of kilobytes. Not only do large view states cause slower downloads, they also lengthen postback request times because the contents of this hidden form field must be included in the HTTP post back request. Unlike most other features of ASP.NET, view state can impact [web pages](https://www.mindstick.com/blog/367/transferring-data-between-asp-dot-net-web-pages) dramatically, not only be in [page size](https://www.mindstick.com/forum/250/page-size) but also in [server side](https://www.mindstick.com/forum/318/how-to-call-javascript-fuction-in-server-side) performance. Moreover, pages with large view states can throw unexpected errors.\

A key thing to remember is that view state is enabled by default for every control on every page. Since many server controls defined on a page [contribute](https://www.mindstick.com/news/2332/japan-will-contribute-500-million-to-the-startup-rapidus-for-manufacturing-processors) to view state size, [your page](https://answers.mindstick.com/qa/32580/how-do-you-pay-facebook-to-help-boost-your-page)’s view state will grow very large and impact performance if left unchecked.

##### When to Disable View State

#####

You can disable a control's view state if the control does not contain any [dynamic data](https://www.mindstick.com/forum/2180/dynamic-data-in-repeater), its value is hard-coded, or its value is assigned on every page request and you're not handling its events.

When you complete a web page, review the controls in the page and consider what information is being passed in the view state and whether you really need all that information to be maintained. To optimize web page size, consider disabling view state in these cases:

• When a page does not postback to itself

• When there are no dynamically set control [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties)

• When the dynamic properties are set with each request of the page

##### How to Disable View State on a Page

#####

To disable a page’s View State, add the code below in the Page class of the page. In this example, the page’s [class name](https://www.mindstick.com/forum/12871/how-to-get-class-name) is ShowOrdersTablePage.

```
public ShowOrdersTablePage(){    this.Init += new EventHandler(Page_Init);} private void Page_Init(object sender, System.EventArgs e){    this.EnableViewState = false;
```

---

Original Source: https://www.mindstick.com/blog/500/enableviewstate-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
