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

適用於

另請參閱