Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Control.IsTrackingViewState Property

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

[Visual Basic]
Protected ReadOnly Property IsTrackingViewState As Boolean
[C#]
protected bool IsTrackingViewState {get;}
[C++]
protected: __property bool get_IsTrackingViewState();
[JScript]
protected function get IsTrackingViewState() : Boolean;

Property Value

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

Remarks

For a sample custom server control that uses this property, see Templated Data-Bound Control Sample.

Example

[Visual Basic, C#, C++] 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. 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.

[Visual Basic] 
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

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

[C++] 
public:
      void DataBind() 
      {
         Control::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();
      }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Web.UI Namespace | ViewState | LoadViewState | SaveViewState

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.