Control.IsTrackingViewState 属性

定义

获取一个值,用于指示服务器控件是否会将更改保存到其视图状态中。Gets a value that indicates whether the server control is saving changes to its view state.

protected:
 property bool IsTrackingViewState { bool get(); };
protected bool IsTrackingViewState { get; }
member this.IsTrackingViewState : bool
Protected ReadOnly Property IsTrackingViewState As Boolean

属性值

如果控件标记为保存其状态,则为 true;否则为 falsetrue if the control is marked to save its state; otherwise, false.

示例

下面的示例重写自定义 ASP.NET 服务器控件中的 DataBind 方法。The following example overrides the DataBind method in a custom ASP.NET server control. 首先,调用基 OnDataBinding 方法,然后使用 ControlCollection 对象。It begins by calling the base OnDataBinding method and then uses the ControlCollection object. ControlCollection.Clear 方法以删除所有子控件和 ClearChildViewState 方法,以删除这些子控件的任何保存的视图状态设置。ControlCollection.Clear method to delete all the child controls and the ClearChildViewState method to delete any saved view-state settings for those child controls. 最后,ChildControlsCreated 属性设置为 trueFinally, the ChildControlsCreated property is set to true. 然后,控件使用 IsTrackingViewState 属性来确定是否为控件启用了视图状态更改跟踪。The control then uses the IsTrackingViewState property to determine whether view-state change tracking is enabled for the control. 如果未启用,则调用 TrackViewState 方法。If it is not enabled, the TrackViewState method is called.

public override void DataBind() 
{
   base.OnDataBinding(EventArgs.Empty);
   // Reset the control's state.
   Controls.Clear();
   // Check for HasChildViewState to avoid unnecessary calls to ClearChildViewState.
   if (HasChildViewState)
      ClearChildViewState();
   ChildControlsCreated = true;
   if (!IsTrackingViewState)
      TrackViewState();
}
Public Overrides Sub DataBind()
   MyBase.OnDataBinding(EventArgs.Empty)
   ' Reset the control's state.
   Controls.Clear()
   ' Check for HasChildViewState to avoid unnecessary calls to ClearChildViewState.
   If HasChildViewState Then
      ClearChildViewState()
   End If
   ChildControlsCreated = True
   If Not IsTrackingViewState Then
      TrackViewState()
   End If
End Sub

注解

有关使用此属性的示例自定义服务器控件,请参阅模板服务器控件示例For a sample custom server control that uses this property, see Templated Server Control Example

适用于

另请参阅