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

適用於

另請參閱