Understand ASP.NET ViewState in Web Forms

 View State is a Dictionary Structure, which is used by ASP.NET to preserve the state of various child controls of the webpage during postback. View State plays a very important role in implementing the postback model of ASP.NET discussed in the previous section. Because Stateful-ness is not possible in ASP.NET web applications without using View State as discussed in the previous section.

Prior to ASP.NET, web-developers doing web development using VBScript Based Classic ASP generally used Hidden Fields to manage Stateful-ness so that the state of various Web Controls of Across Webpage of Successful HTTP-Requests To be maintained.

This approach became even more important when more than one <form> Element was used on the same webpage. Therefore, it was also necessary to use Hidden Fields to find out which Web Form has been submitted by clicking the Associated Submit Button with which <form> Element, under which every <form> Element has a hidden one. There was a field that was programmatically initialized during page rendering.

View State is a much better-extended version of this Approach. Under this, the View State is a Unique and Encoded manner Hidden Field, which stores the values ​​of the various Controls of a WebForm of an ASP.NET Page as a Dictionary Object.

By default, each Page Control saves the Entire State of its page i.e. each Property Value of each Control in the View State. In an average size page, View State holds a few KB of extra data. These data are downloaded into the Client Web Browser during each user request and uploaded to the server. That is, the ViewState object is used as a Carrier for state-transmission between the client and the server.

Although this View State is neither used in the Client Side, nor should it be used, but each Request-Response Cycle has flow between Client-Server to Simulate Statefulness in a Stateless Protocol based Web Application.

That is, the Client Web Browser sends the states of the various Web Controls of the current Webpage to the Web Server itself through the View State and the Web Server, again before sending Resultant Webpage as a Response to the Web Browser. Reuse this View State to fill again with the previous State Values ​​or New Modified Values ​​and to reprieve the State of the various Web Controls of this Dynamically Generated Response Webpage in the next Request to View State of Response Page. Also resets to Client Web Browser as a Hidden Field.

These processes follow circularly in each Request-Response Cycle which results in us getting Feeling or Simulation of Stateful-ness in an ASP.NET Web Application based on a stateless protocol like HTTP.

In the first version of ASP.NET, the kind of work that View State was developed for, it is still doing the same thing today. Whereas in all subsequent versions, different types of modifications have been made to minimize the size of the View State only, so that there is at least data transfer between the client and the server to manage the stateful-ness.

But with the development of new devices over time, its size was again increasing in modern web applications, because RIA (Rich Internet Applications) were being developed due to changing the needs of people and in such applications, the state To manage, again a lot of data transfer was started in the View State between the client-servers.

Although we could still create ASP.NET Webpages that use View State sparingly, but still ASP.NET according to its Fundamental Concept can use State View to manage State between Client and Server. Through this, he used to transfer some data.

That is, in an ASP.NET WebForms based web application, we could not completely eliminate the View State Concept in any case because State Management was not possible in WebForms based web applications without using View State Concept and View State To completely eliminate from an ASP.NET application, it was necessary to completely redesign the ASP.NET platform.

So a new feature was added in ASP.NET 4, which provides more Web Controls to the developers, which keeps the size of the View State to a minimum but does not affect the functionality of the page in any way.

Leave a comment