StateBag に格納されている StateItem オブジェクトを確認して、 Control.TrackViewState への呼び出し以降にそのオブジェクトが変更されたかどうかを評価します。
Public Function IsItemDirty( _
ByVal key As String _) As Boolean
[C#]
public bool IsItemDirty(stringkey);
[C++]
public: bool IsItemDirty(String* key);
[JScript]
public function IsItemDirty(
key : String) : Boolean;
パラメータ
- key
チェックする項目のキー。
戻り値
項目が変更された場合は true 。それ以外の場合は false 。
解説
キー パラメータが StateBag に存在しない場合、このメソッドは false も返します。
使用例
[Visual Basic, C#, C++] IsItemDirty メソッドを使用する例を次に示します。
' 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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ
参照
StateBag クラス | StateBag メンバ | System.Web.UI 名前空間 | ViewState