Export (0) Print
Expand All

StateBag.Clear Method

Removes all items from the current StateBag object.

[Visual Basic]
Public Overridable Sub Clear() Implements IDictionary.Clear
[C#]
public virtual void Clear();
[C++]
public: virtual void Clear();
[JScript]
public function Clear();

Implements

IDictionary.Clear

Example

[Visual Basic, C#, C++] The following example demonstrates using the Clear method.

[Visual Basic] 
' Implement the SaveViewState method. If the StateBag
' that stores the MyItem class's view state contains
' a value for the message property and if the value
' has changed since the TrackViewState method was last 
' called, all view state for this class is deleted, 
' using the StateBag.Clear method,and the new value is added.
Function SaveViewState() As Object Implements IStateManager.SaveViewState
   ' Check whether the message property exists in 
   ' the ViewState property, and if it does, check
   ' whether it has changed since the most recent
   ' TrackViewState method call.
   If Not CType(_viewstate, IDictionary).Contains("message") OrElse _viewstate.IsItemDirty("message") Then
      If (True) Then
         _viewstate.Clear()
         ' Add the _message property to the StateBag.
         _viewstate.Add("message", _message)
      End If
   End If
   Return CType(_viewstate, IStateManager).SaveViewState()
End Function 'IStateManager.SaveViewState



[C#] 
// Implement the SaveViewState method. If the StateBag
// that stores the MyItem class's view state contains
// a value for the message property and if the value
// has changed since the TrackViewState method was last 
// called, all view state for this class is deleted, 
// using the StateBag.Clear method,and the new value is added.
object IStateManager.SaveViewState()
{
   // Check whether the message property exists in 
   // the ViewState property, and if it does, check
   // whether it has changed since the most recent
   // TrackViewState method call.
   if( (!((IDictionary)_viewstate).Contains("message")) || (_viewstate.IsItemDirty("message")))
   {
      {
         _viewstate.Clear();
         // Add the _message property to the StateBag.
         _viewstate.Add("message", _message);
      }
   }
   return ((IStateManager)_viewstate).SaveViewState();
}


[C++] 
// Implement the SaveViewState method. If the StateBag
// that stores the MyItem class's view state contains
// a value for the message property and if the value
// has changed since the TrackViewState method was last
// called, all view state for this class is deleted,
// using the StateBag::Clear method, and the new value is added.
Object* IStateManager::SaveViewState() {
   // Check whether the message property exists in
   // the ViewState property, and if it does, check
   // whether it has changed since the most recent
   // TrackViewState method call.
   if ((!(dynamic_cast<IDictionary*>(_viewstate))->Contains(S"message")) || (_viewstate->IsItemDirty(S"message"))) { {
      _viewstate->Clear();
      // Add the _message property to the StateBag.
      _viewstate->Add(S"message", _message);
   }
   }
   return (dynamic_cast<IStateManager*>(_viewstate))->SaveViewState();
}

[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

StateBag Class | StateBag Members | System.Web.UI Namespace | Remove | Add

Show:
© 2014 Microsoft