WebControl.SaveViewState 方法

定義

儲存叫用 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

傳回

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 is the cumulative values of the properties for a server control. 這些值會自動放在 ViewState 伺服器控制項的屬性中,也就是類別的實例 StateBagThese 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.

當儲存檢視狀態時,此字串物件會傳回至用戶端,做為儲存在隱藏的 HTML 元素中的變數 inputWhen 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 方法並修改伺服器控制項的屬性,來改善效率 ViewStateWhen 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.

適用於

另請參閱