Geeks With Blogs
Create Fun Things - Samer's Developer Blog Development Blog for C#, .NET and Obj-C

So I’m pretty sure I’ve read about a thousand articles regarding ViewState and whether or not people should enable it on every thing, ever, or go ahead and disable it on the page level as the second thing you do after creating a new .aspx page.

I’ve been working with .NET now for about seven months and started out pretty much letting viewstate do its default thing. It seemed great. I didn’t really notice any performance hits so I just kept doing it.

Now that the application has grown significantly (been working on the same app this entire year), Viewstate is rearing its ugly head. There are a few pages that drag with the size of viewstate and honestly, it doesn’t really add anything to the pages.

Using Fiddler2 (the greatest app ever), I have started disabling ViewState on several controls and ListViews, and all those panels, tab controls, etc. The result has been pretty great.

I haven’t finished going through everything and I’ve already seen post back size reductions by 5-10%. I’ve also seen first page hit sizes reduced by 20-25%. All this adds up to faster page loads, faster post backs and a better user experience!

Anyway, so whenever you start writing that new ASP.NET application, you should actually consider disabling it as you go along. For most purposes, it’s really not required, and you save a lot of page overhead disabling it.

Also of note: When I was watching the developer conference on .NET 4.0 several months ago, the .NET guys themselves noted that they “went overboard” with Viewstate. I believe in 4.0 (Unless something has changed), ViewState is disabled by default on the page, and you enable it as you need. (Basically the opposite of what is available today in 3.5)

Posted on Tuesday, July 21, 2009 8:58 PM | Back to top

Comments on this post: Viewstate: Friend or foe?

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © samerpaul | Powered by: