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


保存调用 TrackViewState() 方法后修改的任何状态。Saves any state that was modified after the TrackViewState() method was invoked.

 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 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.

保存视图状态时,此字符串对象将作为存储在隐藏的 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.