jump to navigation

Viewstate management and ASP.Net 4.0 June 27, 2009

Posted by fofo in ASP.NET 4.0, VS 2010.
Tags: ,
trackback

For people who have been following this blog for some time, they know my favourite subject is ASP.NET.

I think this is the best platform for building web applications nowadays. In ASP.NET 4.0 we have some very interesting new enhancements and new features.

I will try to talk about all of them in separate posts since some people have been complaining that my posts are too long.

In this post I will talk about Viewstate management in ASP.NET 4.0.

Let’s have a look first what really Viewstate is and what it really does.Unless you move to a new paradigm for building web applications like ASP.NET MVC you must have a good knowledge of Viewstate.

Viewstate represents the state of the page when it was last processed on the server. We use it to retain values across two successive requests for the same page. It is a hidden field added to the page and is restored on the server before the page request is processed. The Viewstate information travels back and forth with the page itself, but contains no visual elements that need to be rendered. So you must be thinking that this is fantastic news for the web developer. But (there is always a but), the extra information in the Viewstate adds to the size of the page and the information that travels down the wire. I have seen web pages that have an additional 20Kbytes of Viewstate information.

Every .aspx page derives from the Page class or Page control and extends it. The default value for the EnableViewState property for the page is True. Through that property we can get or set(enable-disable)  the view state of the control.

If we disable ViewState on page level, you cannot enable it on child controls. if you go to the web.config and type

<pages enableViewState=”false”>

then if you try to enable it on child controls is impossible.

In ASP.NET 4.0 we have the ViewState property. There are 3 values for this property:enabled, disabled, inherit .

We can use this property to enable Viewstate for an individual control even if Viewstate is disabled for the page. We can disable the Viewstate for a control even if it is enabled on a page level.

Add to FacebookAdd to NewsvineAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to Ma.gnoliaAdd to TechnoratiAdd to Furl

Comments»

1. jhony - July 10, 2009

wonderful

2. nikos Gemelos - September 10, 2009

excellent post.Microsoft finally dealt with the flaws of Viestate management


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: