ASP.NET 4.0 : ViewStateMode (New Property)

Virendradugar
Posted by in ASP.NET category on for Beginner level | Views : 13673 red flag

This article explains about the new property of ASP.NET 4.0
Introduction

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.

What's new?

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..


Page copy protected against web site content infringement by Copyscape

About the Author

Virendradugar
Full Name: Virendra Dugar
Member Level: Silver
Member Status: Member,MVP
Member Since: 8/11/2009 4:14:05 AM
Country: India

http://jquerybyexample.blogspot.com
Virendra Dugar is experienced Senior Software Developer with over 5 years of hands-on experience working with Microsoft .NET technology (ASP.NET, C#, VB.NET,SQL Server). He is always keen to learn new technology. He holds a Master's Degree in Computer Application & Information technology from Gujarat University in india.In free time, he loves to listen music, read books, play games and do blogging etc. Visit his blogs : http://jquerybyexample.blogspot.com

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)