---
title: "View State in ASP.NET"  
description: "The web is state-less protocol, so the page gets instantiated, executed, rendered and then disposed on every round trip to the server. The developers"  
author: "Amit Singh"  
published: 2010-11-06  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/46/view-state-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# View State in ASP.NET

The web is ***state-less** protocol*, so the page gets instantiated, executed, rendered and then disposed on every round trip to the server. The [developers](https://www.mindstick.com/blog/302688/handling-errors-in-rust-a-comprehensive-guide-for-developers) code to add "statefulness" to the page by using Server-side storage for the state or posting the page to itself. When require to persist and read the data in control on webform, [developer](https://www.mindstick.com/articles/157260/variation-between-web-designer-and-web-developer) had to read the values and store them in hidden variable (in the form), which were then used to restore the values. With advent of .NET [framework](https://www.mindstick.com/forum/34615/software-framework-vs-library), ASP.NET [came up](https://answers.mindstick.com/qa/41115/who-came-up-with-the-10-percent-plan-what-did-this-plan-say) with [ViewState](https://www.mindstick.com/blog/326/viewstate-in-asp-dot-net) mechanism, which tracks the data values of server controls on ASP.NET webform. In effect, ViewState can be viewed as "*hidden variable managed by ASP.NET framework!*". When ASP.NET page is executed, data values from all server controls on page are collected and encoded as single string, which then assigned to page's hidden atrribute "< input type=hidden >", that is part of page sent to the client.\

\
*ViewState value is temporarily saved in the client's browser.ViewState can be disabled for a single control, for an entire page orfor an entire [web application](https://www.mindstick.com/articles/13069/progressive-web-application-pwas-all-you-need-to-know-about). The syntax is:*\
Disable ViewState for control (Datagrid in this example)\
< asp:datagrid [EnableViewState](https://www.mindstick.com/interview/734/what-does-the-enableviewstate-property-signify)="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 through entry in [web.config](https://www.mindstick.com/forum/183/web-config-file)\
< Pages EnableViewState="false" ... / >\
\

---

Original Source: https://www.mindstick.com/blog/46/view-state-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
