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 to view state size, 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, 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
• 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 is ShowOrdersTablePage.
this.Init += new EventHandler(Page_Init);
private void Page_Init(object sender, System.EventArgs e)
this.EnableViewState = false;