Control.IsTrackingViewState Property

Definition

Gets a value that indicates whether the server control is saving changes to its view state.

C#
protected bool IsTrackingViewState { get; }

Property Value

true if the control is marked to save its state; otherwise, false.

Examples

The following example overrides the DataBind method in a custom ASP.NET server control. It begins by calling the base OnDataBinding method and then uses the ControlCollection object. ControlCollection.Clear method to delete all the child controls and the ClearChildViewState method to delete any saved view-state settings for those child controls. Finally, the ChildControlsCreated property is set to true. The control then uses the IsTrackingViewState property to determine whether view-state change tracking is enabled for the control. If it is not enabled, the TrackViewState method is called.

C#
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();
}

Remarks

For a sample custom server control that uses this property, see Templated Server Control Example.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also