---
title: "ViewState in ASP.NET"  
description: "When a form is submitted in classic ASP, all form values are cleared. Suppose you have submitted a form with a lot of information and the server comes"  
author: "AVADHESH PATEL"  
published: 2012-07-27  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/326/viewstate-in-asp-dot-net  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# ViewState in ASP.NET

When a form is submitted in classic ASP, all form values are cleared. Suppose you have submitted a form with a lot of information and the server comes back with an error. You will have to go back to the form and correct the information. You click the back button, and what happens.......ALL form values are CLEARED, and you will have to start all over again! The site did not [maintain your](https://answers.mindstick.com/qa/99988/how-to-maintain-your-health-during-summers) [ViewState](https://www.mindstick.com/forum/2168/viewstate-in-a-httphandler).\

When a form is submitted in ASP .NET, the form reappears in the browser window [together](https://yourviews.mindstick.com/view/80819/live-in-relationship-protecting-the-right-to-live-together) with all form values. How come? This is because ASP .NET maintains your ViewState. The ViewState indicates the status of the page when submitted to the server. The status is defined through a hidden field placed on each page with a <form runat="server"> control. The source could look something like this: View source of page.

Maintaining the ViewState is the default setting for [ASP.NET](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) [Web Forms](https://www.mindstick.com/interview/33689/is-mvc-replacing-asp-dot-net-web-forms). If you want to NOT maintain the ViewState, include the directive <%@ Page [EnableViewState](https://www.mindstick.com/interview/734/what-does-the-enableviewstate-property-signify)="false" %> at the top of an .aspx page or add the [attribute](https://www.mindstick.com/blog/221/attributes-reflection) EnableViewState="false" to any control.

##### ViewState can be disabled for a single control, for an entire page or for an

##### entire web application.

##### \

##### The syntax is:

· Disable ViewState for control (Datagrid in this example)

< asp:datagrid EnableViewState="false" ... / >

· Disable ViewState for a page, using [Page directive](https://www.mindstick.com/interview/999/explain-the-use-of-duration-attribute-of-outputcache-page-directive)

< %@ Page EnableViewState="False" ... % >

· Disable ViewState for [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) through entry in [web.config](https://www.mindstick.com/forum/183/web-config-file)

< Pages EnableViewState="false" ... / >

---

Original Source: https://www.mindstick.com/blog/326/viewstate-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
