Click here to Skip to main content
15,883,883 members
Articles / Web Development / ASP.NET
Article

Better View State Management in ASP.NET 4.0

Rate me:
Please Sign up or sign in to vote.
2.00/5 (3 votes)
11 Oct 2013CPOL2 min read 9.3K   3   1
ASP.NET is a great platform to develop any web applications. From ASP.NET 1.1 we are having one feature called View State which store the data in

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

ASP.NET is a great platform to develop any web applications. From ASP.NET 1.1 we are having one feature called View State which store the data in hidden field during page post back. Any Serializable data can be stored in View State. It’s scope is limited to page post backs.View state is great if you use it wisely otherwise it may create problem with performance page. I have seen that there were some page which contains lots of view state. It will increase your Kilo bytes of page and increase page rendering time.

In ASP.NET 4.0 we have more control over maintaining view state for page let’s see how we can manage View State more efficiently in asp.net 4.0. In the earlier version of asp.net we have View State optional that means we can turn View State view EnableViewState property. If we made it true then it will enabled other wise it will be disabled for that page. All controls that are derived from control class will have EnableViewstate property. Now in earlier version of ASP.NET this property will be ignored for the child controls. For example if you enabled this property for page and now you have three textboxes on page then that textbox’s value will be stored in View State regardless of textbox’s EnableViewState Property is true or not.

But with ASP.NET 4.0 things are different with respect to above scenario. Now we have one more property called ViewStateMode Property. This property help us greatly in managing View State. It has there values Enabled,Disabled,Inherit. With this property you can enable View State of control even if View State is disabled. So now we will have facility to turn off the View State of parent controls like page and then we can decide which control will have View State enabled.

In ASP.NET 4.0 ViewStateMode property will accept following values.

  • Enabled- This will enable View State for particular control and also for any child control which have ‘Inherit’ value for this property or nothing set for this property.
  • Disabled- This will disable View State for that particular control.
  • Inherit- This will specify that control will use the parent control ViewStateMode property.

Hope this will help you understanding View State Management in ASP.NET 4.0.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.

The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
This is a Collaborative Group

754 members

Comments and Discussions

 
GeneralMy vote of 2 Pin
Pramod Kamath13-Mar-14 3:31
Pramod Kamath13-Mar-14 3:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.