In ASP. net1.1, to improve performance, I believe many programmers will close viewstate on the page, but the benefits of viewstate are self-evident. Fortunately, ASP. net2.0 has greatly improved viewstate performance. Next, let's make a simple experiment. At the same time, we have only one calendar control on the ASP. net1.1 page and ASP. net2.0 page. After the page is loaded, compare the value of viewstate:
ASP. net1.1:
Ddwtmtg1ndkwmjc0nzs7pl12vfm8r/3kar2g84154cbwth7u
ASP. net2.0:
/Wepdwullteznjg5mjaxmzhkzm3popw3dbraqefygzi077prcrtt
Why is ASP. net2.0 longer than ASP. net1.1? Don't worry. Check the value changes after PostBack:
ASP. net1.1:
Ddwtmtg1ndkwmjc0nzt0pdtspgk8mt47pjtsphq8o2w8atwxpjs +
O2w8ddxamdxwpha8bdxtrds + o2w8bdxtexn0zw0urgf0zvr
Pbwusig1zy29ybglilcbwzxjzaw9upteumc41mdawljasien
1bhr1cmu9bmv1dhjhbcwguhvibgljs2v5vg9rzw49yjc3ytvj
Ntyxotm0zta4otwymda2lta3ltezpjs + oz4 + oz47ozs7ozs7
Ozs7pjs7pjs + PJs + 9 eokiaze + 12gw74bc8stbzya2k4 =
ASP. net2.0:
/Wepdwullteznjg5mjaxmzgpzbycagmpzbycageppcsacgeadx
Ychgjtrbybbgcalgndemgizgrk9ch1ooefjno + 6uh0iki2sfshcu =
Obviously, the viewstate value in 2.0 is much smaller than that in 1.0, which greatly improves the performance. The reason is simple. In 1.1, losformatter is used to serialize viewstate data, while in 2.0, a dedicated class objectstateformatter is used to serialize and deserialize viewstate data. Losformatter uses textwriter, while objectstateformatter uses binarywriter, so that bytes is used in 2.0 to keep viewstate rather than string as in 1.1. For example, an integer variable requires four bytes of viewstate data in 1.1, and only one byte in 2.0.
For more information about objectstateformatter, see:
Http://msdn2.microsoft.com/zh-cn/library/system.web.ui.objectstateformatter.aspx