Export (0) Print
Expand All

IStateManager.SaveViewState Method

When implemented by a class, saves the changes to a server control's view state to an Object.

[Visual Basic]
Function SaveViewState() As Object
[C#]
object SaveViewState();
[C++]
Object* SaveViewState();
[JScript]
function SaveViewState() : Object;

Return Value

The Object that contains the view state changes.

Example

[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

IStateManager Interface | IStateManager Members | System.Web.UI Namespace | Introduction to Web Forms State Management | StateBag | StateItem

Show:
© 2014 Microsoft