asp.net viewstate is a wonderful invention, but can bloat your html. For most users this is probably going to have minimal impact on the page load time. But for search engines spiders you really want to minimise needless information, especially near the top of the page.
It’s best practice to turn off viewstate for the whole page or for individual usercontrols if they don’t require viewstate. The deciding factor here is: does the page or usercontrol perform postbacks.
Even with careful pruning of viewstate you’ll probably find your viewstate is still large…
What you can do
Now there are a couple of strategies I’ve seen for working round this, both involve overriding the page
1 is to intercept the page rendering and move the viewstate hidden variable to the bottom of the page.
Here’s an example http://www.dotnetdiary.com/labels/Moving%20ViewState%20Field.html
2 is a very clever solution that keeps the viewstate information on the server and justs passes a key back and forth to the client.
I read about this approach here http://www.eggheadcafe.com/articles/20040613.asp
Here’s my approach
Now since I don’t think that viewstate bloat has too much of an impact on page performance for real users I’m only going to worry about search engine spiders.
asp.net has a way of detecting spiders – now I’m not saying it’s going to be 100% accurate but in my tests it’s been accurate enough for this technique.
In the page load of your page (or master page)
If Request.Browser.Crawler Then Page.EnableViewState = False
er that’s it, pretty simply eh? 🙂
You can verify if this is working by viewing the source of the cached version of the page that google holds.
Hope that helps!