This documentation is archived and is not being maintained.

StateBag.IsItemDirty Method

Checks a StateItem object stored in the StateBag to evaluate if it has been modified since the call to Control.TrackViewState.

[Visual Basic]
Public Function IsItemDirty( _
   ByVal key As String _
) As Boolean
[C#]
public bool IsItemDirty(
 string key
);
[C++]
public: bool IsItemDirty(
 String* key
);
[JScript]
public function IsItemDirty(
   key : String
) : Boolean;

Parameters

key
The key of the item to check.

Return Value

true if the item has been modified; otherwise, false.

Remarks

This method also returns false if the key parameter does not exist in the StateBag.

Example

[Visual Basic, C#, C++] The following example demonstrates using the IsItemDirty 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 | ViewState

Show: