Forum Moderators: open
I got a kick out of seeing javascript instead of VB script or JScript generated by the microsoft product.
I think this, plus the viewstate tend to create unnecessary round trips and performance drains in .NET (Viewstate creates performance drains-stores a bunch of junk in your HTML)
The cost of viewstate is minimal. Even if you have a huge amount of it, the cost is less than that one additional icon graphic that you placed on the page. If I was trying to reduce the size of the page, I'd first optimize graphics, not viewstate. (Viewstate, for those lurking on this thread, is information that .NET places encoded in a hidden field on the form that stores the original state of the controls on the form before the postback.)
This is how viewstate looks:
<input type="hidden" name="__VIEWSTATE" value="dDwtMTQ2NjgyODI2MTt0PDtsPGk8MT47PjtsPHQ8O2w8aTwxMz47aTwyMT47aTwyMz47aTwyNz47aTwyOT47aTwzOT4
7PjtsPHQ8dDxwPHA8bDxEYXRhVGV4dEZpZWxkO0RhdGFWYWx1ZUZpZWxkOz47bDxDaXR5O0NpdHlDb2RlOz4+Oz47dDxpPDQ3P
jtAPEFsZ29uYTtBdWJ1cm47QmVsbGV2dWU7QmxhY2sgRGlhbW9uZDtCb3RoZWxsO0J1Y2tsZXk7QnVyaWVuO0Nhcm5hdGlvbjt
... and so on ...
Oh yeah, I forgot to mention the obvious thing - this 20 KB is going back to the server every time the form is submitted.
MARK ANDERS: part of the magic of ASP.NET is, by having this concept of these server controls that encapsulate a lot of the functionality for you, it really gives you a nice way of encapsulating the different behavior that you expect, or the different renderings that you expect for different types of devices. And we do this in a lot of different scenarios; for example, we have a set of controls for doing validation, which is a very, very complicated thing to do in a web site, especially when you want to, you know, emit script code that goes down to the client and does the validation; you also want to have server-side validation for down level browsers. And we have a set of controls that will automate all of that for you. So they encapsulate the basic validation behavior, yet, if it's a rich browser, they will emit one thing, they'll emit -- script code. And if it's a down level, they'll run the validation and produce the exact same experience, except it's happening server-side, for those down level browsers.
And it will also automatically handle scenarios where clients that deliberately try to go around client-side script or deactivate client script and spoof things, it will trap those as well. And all you need to do is drop these on your page, declaratively as tags, and you can write two or three line of code against them, and you actually have a fully validated page.
I think most ASPX pages have controls that have EnableViewState set to true that don't need it.
If I wanted to maintain state using Viewstate I would have to enable it on all of the controls. There is no point in enabling view state just on some of the controls, then I would have to write my own code to maintain state for them and I might as well do it for all of the controls then.
By default viewstate is enabled for web form controls, so I guess that is why most people don't disable it and maintain state and don't even know about it.