public knowledge blog_load(sender Virendra)

                                                                                                                          Nothing shocks me, I am a Software Engineer.

ASP.NET 4.0 : ViewStateMode (New Property)

Posted by Virendra Dugar on May 17, 2009

ViewState is a very misunderstood animal. ViewState is a headache for the programmers. Programmers leave it enable for all the controls even if there is no need to persist their value. Right use of ViewState can increase the performance of the page drastically.

Before I discuss about this new property, let’s come back to the current era of ASP.NET 3.5 or previous version of .NET. What if you turn off ViewState at page level and make it on at control level? Ask yourself, is it possible with previous versions of .NET (upto 3.5)? Sorry but there is a bad news that it’s not possible. But there is a good news as well. You can achieve this with new version of ASP.NET that is 4.0.

ASP.NET 4.0 comes with new and cool property ViewStateMode. It has 3 possible values.

  1. Enabled : This turns on the ViewState for the control.
  2. Disabled : This turns off the ViewState for the control.
  3. Inherit : Takes the value from the parent and set it accordingly. If it has been set to Disabled at Page level and for textbox you set ViewStateMode = “Inherit” then it will disable the ViewState for the textbox.

The main difference between EnableViewState and ViewStateMode property is, if EnableViewState property is set to disabled at parent level, there is no way of making viewstate enable at control level, But this is possible with this new property :ViewStateMode.

It’s really cool and simple.. is n’t it? 

Enjoy..

Advertisements

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: