A list of good articles to help understand ASP.NET ViewState
ViewState: All You Wanted to Know
ViewState and JavaBean The ASP.NET Alternative part give us a overview of how ViewStae works
Taking a Bite Out of ASP.NET ViewState is another MSDN article
Understanding ASP.NET View State by Scott Mitchell from 4GuysFromRolla.com is the lastes MSDN article about ViewState
以下是個人的一些理解:
ASP.NET的一大好處就是很多html control 都可以設定為runat=“server“,變成可以在伺服器端控制的control.
這也是導致誤解ViewState的一個原因。
ViewState不是用來恢複Form(此處Form專門指普通的,用來向伺服器端提交資料的表單)的值(value)的.
比如Input 裡面的TextBox,Submit, CheckBox, Select等等,這些control由於實施了IPostBackDataHandler介面,所以他們的value並沒有儲存在ViewState裡面,因此也不用ViewState來恢複.
但是他們的其他屬性比如background color等,如果有的話是要儲存在ViewState裡面的.
ViewState是用來恢複和儲存那些
被設定為runat=”server”的,
沒有實施了IPostBackDataHandler介面的,
control的屬性.是屬性,不僅僅是值.
比如Label, Calendar等等和其他微軟自己引入的control.