Control.HasChildViewState Property

Definition

Gets a value indicating whether the current server control's child controls have any saved view-state settings.

protected bool HasChildViewState { get; }

Property Value

true if any child controls have saved view state information; otherwise, false.

Examples

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

You can avoid unnecessary calls to the ClearChildViewState method by using this property to verify that any child controls of the server control are storing view-state information.

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