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.
I think the DotNetNuke developers were the first to realize that moving the viewstate to the bottom of the page makes the page much more Google-friendly. Google only indexes the first (n) bytes of the page, so if you have 12 kb of Base64 encoded schmutz in your header, that isn't exactly helping people find your pages via Google searches. Scott Mitchell compares and contrasts several methods of moving the viewstate input field to the bottom of the HTML form.
The benefits from compressing viewstate are somewhat marginal, nowhere near what you'd get from zipping plain text. but it's still worth trying. Scott Hanselman points us to a nifty base page class that automagically compresses viewstate for you.
There's also an interesting article on eggheadcafe about moving viewstate to the server. Peter Bromberg benchmarks the performance difference between viewstate on the client, and viewstate on the server in Session, Application, or Cache.
ASP.NET 2.0 brings a few much-needed improvements to Viewstate:
Here's to progress. Now pardon me while I crack my bullwhip. Hyaa!!
Posted by Jeff Atwood View blog reactions
« The Best of Creative Computing Microchip Easter Eggs »
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.
Peter Bridger on October 13, 2005 04:44 AMI 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..
Jeff Atwood on October 13, 2005 12:25 PM'
' on November 23, 2006 04:44 AM| Content (c) 2008 Jeff Atwood. Logo image used with permission of the author. (c) 1993 Steven C. McConnell. All Rights Reserved. |