Managing View State in ASP.NET 4 Using the New ViewStateMode Property

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
The ASP.NET Web Forms model strives to encapsulate the lower level complexities involved in building a web application. Features like server-side event handlers, thepage lifecycle, and view state effectively blur the line between the client and the server, simplifystate management, and free the developer from worrying about HTTP, requests and responses, and similar matters. While these facets of the Web Forms model allow forrapid application development and make ASP.NET more accessible to developers with a web application background, their behavior can impact your websites behavior andperformance.

View state is perhaps the most important - yet most misunderstood - feature of the Web Forms model. In a nutshell, view state is a technique that automatically persistsprogrammatic changes to the Web controls on a page. By default, this state is serialized into a base-64 encoded string and included as a hidden field in the Web Form. On postback, this state information is returned to the server as part of the POST request, at which point the server can deserialize it andreapply the persisted state to the controls in the control hierarchy. (If this last paragraph made crystal clear sense, great! If not, consider readingmy article, Understanding ASP.NET View State, and Dave Reedsarticle, ViewStateMode in ASP.NET 4, before continuing.)

One potential issue with view state is that it can greatly bloat the size of your web pages. Each new version of ASP.NET seems to include new techniques for managing view states footprint. ASP.NET 4 adds a new property to all Web controls, ViewStateMode, which allows developers to disable view state for a page by default and then selectively enable it for specific controls. This article reviews existing view state-related properties and then delves into the new ViewStateMode property. Read on to learn more!
Read More >



More...
 
Back
Top