WebControl.SaveViewState WebControl.SaveViewState WebControl.SaveViewState WebControl.SaveViewState Method

定義

儲存叫用 TrackViewState() 方法後已修改的任何狀態。Saves any state that was modified after the TrackViewState() method was invoked.

protected:
 override System::Object ^ SaveViewState();
protected override object SaveViewState ();
override this.SaveViewState : unit -> obj
Protected Overrides Function SaveViewState () As Object

傳回

包含控制項目前檢視狀態的物件;如果沒有任何檢視狀態與控制項產生關聯,則為 nullAn object that contains the current view state of the control; otherwise, if there is no view state associated with the control, null.

備註

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

View state 是伺服器控制項屬性的累計值。View state is the cumulative values of the properties for a server control. 這些值會自動放在伺服器ViewState控制項的屬性中,這是StateBag類別的實例。These values are placed automatically in the ViewState property for the server control, which is an instance of the StateBag class. ViewState屬性值接著會在伺服器控制項生命週期的 [儲存狀態] 階段之後保存到字串物件中。The ViewState property value is then persisted to a string object after the save state stage of the life cycle for the server control. 如需詳細資訊,請參閱ASP.NET 網頁生命週期總覽For more information, see ASP.NET Page Life Cycle Overview.

儲存 view 狀態時,會將此字串物件傳回給用戶端,做為儲存在隱藏 HTML input元素中的變數。When view state is saved, this string object is returned to the client as a variable that is stored in a hidden HTML input element. 當您撰寫自訂伺服器控制項時,您可以藉由覆SaveViewState寫方法並修改ViewState伺服器控制項的屬性,來提升效率。When you author custom server controls, you can improve efficiency by overriding the SaveViewState method and modifying the ViewState property for your server control. 如需詳細資訊,請參閱ASP.NET 狀態管理總覽For more information, see ASP.NET State Management Overview.

適用於

另請參閱