Control.IsTrackingViewState Control.IsTrackingViewState Control.IsTrackingViewState Control.IsTrackingViewState Property

定義

取得值,指出伺服器控制項是否正在儲存檢視狀態的變更。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.

範例

下列範例會覆寫DataBind自訂 ASP.NET 伺服器控制項中的方法。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

適用於

另請參閱