StateManagedCollection.IStateManager.SaveViewState 方法


儲存自頁面回傳至伺服器以來 StateManagedCollection 集合和每個內含 IStateManager 物件的變更。Saves the changes to the StateManagedCollection collection and each IStateManager object it contains since the time the page was posted back to the server.

 virtual System::Object ^ System.Web.UI.IStateManager.SaveViewState() = System::Web::UI::IStateManager::SaveViewState;
object IStateManager.SaveViewState ();
abstract member System.Web.UI.IStateManager.SaveViewState : unit -> obj
override this.System.Web.UI.IStateManager.SaveViewState : unit -> obj
Function SaveViewState () As Object Implements IStateManager.SaveViewState



包含 StateManagedCollection 和內含項目之檢視狀態變更的物件。The object that contains the changes to the view state of the StateManagedCollection and the items it contains. 如果沒有與集合及其項目關聯的檢視狀態,則這個方法會傳回 nullIf no view state is associated with the collection and its elements, this method returns null.



這個方法主要由控制項開發人員使用。This method is used primarily by control developers.

檢視狀態是伺服器控制項屬性值的累積。View state is the accumulation of the values of a server control's properties. 這些值會自動放在伺服器控制項的 ViewState 屬性中,也就是類別的實例 StateBagThese values are automatically placed in the server control's ViewState property, which is an instance of the StateBag class. 然後,這個屬性的值會在伺服器控制項生命週期的儲存狀態階段之後保存到字串物件。This property's value is then persisted to a string object after the save state stage of the server control life cycle. 如需詳細資訊,請參閱 ASP.NET Web 服務器控制項For more information, see ASP.NET Web Server Controls.

當儲存檢視狀態時,此字串物件會傳回至用戶端,做為儲存在 HTML 隱藏專案 () 的變數 <input type="hidden">When view state is saved, this string object is returned to the client as a variable that is stored in an HTML hidden element (<input type="hidden">). 當您撰寫自訂伺服器控制項時,您可以藉由覆寫這個方法和修改伺服器控制項的屬性,來改善效率 ViewStateWhen you author custom server controls, you can improve efficiency by overriding this method and modifying your server control's ViewState property. 如需詳細資訊,請參閱 ASP.NET Web 服務器控制項ASP.NET 狀態管理總覽For more information, see ASP.NET Web Server Controls andASP.NET State Management Overview.