Wrangling ASP.NET Viewstate

Inspired by Scott Hanselman's recent post on ASP.NET viewstate wrangling, here's a roundup of tips for dealing with that ornery viewstate stuff. The first rule of thumb, of course, is to turn it off whenever you can. But sometimes you can't.


This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2005/10/wrangling-aspnet-viewstate.html

To be honest, even though I’m developing in .net 2 beta 2, I’ve still not fully embrased the new ‘.net way’ of doing things.

I primarly use Web Matrix for my asp.net development, as I like to get close to the metal.
I’d rather hand code a repeater in Web Matrix than drag’n’drop a datagrid in Visual Studio.

That’s not to say I’m doing things slowly, I resently re-developed a .net v1 project I did two years ago, which took two months. Re-developing it in .net v2 took me two weeks.

The viewstate is very useful sometimes, but I really don’t like to rely on something whichout fully understanding it. Even then, there’s normally a better way, if you’re willing to put the effort in.

I should have also linked to Fritz Onion’s viewstate/controlstate decoders:

http://www.pluralsight.com/tools.aspx

There is an web decoder for 1.x viewstate here:

http://www.wilsondotnet.com/Demos/ViewState.aspx

I never found decoded viewstate to be particularly illuminating, but for what it’s worth…