StateBag.Item[String] 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置存储在对象中的 StateBag 项的值。
public:
property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ key); void set(System::String ^ key, System::Object ^ value); };
public object this[string key] { get; set; }
member this.Item(string) : obj with get, set
Default Public Property Item(key As String) As Object
参数
- key
- String
项的键。
属性值
对象中的 StateBag 指定项。
示例
下面的代码示例演示了一个属性,该属性将其名称和值保存为属性的键/值对 Control.ViewState 。 该 ViewState 属性是类的 StateBag 实例。
// Add property values to view state with set;
// retrieve them from view state with get.
public String Text
{
get
{
object o = ViewState["Text"];
return (o == null)? String.Empty : (string)o;
}
set
{
ViewState["Text"] = value;
}
}
' Add property values to view state with set;
' retrieve them from view state with get.
Public Property [Text]() As String
Get
Dim o As Object = ViewState("Text")
If (IsNothing(o)) Then
Return String.Empty
Else
Return CStr(o)
End If
End Get
Set(ByVal value As String)
ViewState("Text") = value
End Set
End Property
注解
使用此成员是保存和检索控件或页面的视图状态值的最简单方法。
如果在设置此属性时尚未将项存储在对象中 StateBag ,则其键/值对将添加到集合中。 如果将此属性 null 设置为在对项调用方法之前 TrackViewState ,将从对象中删除 StateBag 该属性。 否则,将此属性 null 设置为键时,将保存以允许跟踪项的视图状态。