StateBag.Item Property

Gets or sets the value of an item stored in the StateBag object.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

public:
property Object^ default [String^] {
	Object^ get (String^ key);
	void set (String^ key, Object^ value);
}
/** @property */
public Object get_Item (String key)

/** @property */
public void set_Item (String key, Object value)

Not applicable.

Parameters

key

The key for the item.

Property Value

The specified item in the StateBag object.

Using this member is the simplest way to save and retrieve view-state values for a control or a page.

If an item is not already stored in the StateBag object when you set this property, its key/value pair is added to the collection. If you set this property to a null reference (Nothing in Visual Basic) before the TrackViewState method is called on an item, it is removed from the StateBag object. Otherwise, when you set this property to a null reference (Nothing in Visual Basic) the key is saved to allow tracking of the item's view state.

The following code example demonstrates a property that saves its name and value as a key/value pair to the Control.ViewState property. The ViewState property is an instance of the StateBag class.

No code example is currently available or this language may not be supported.
// Add property values to view state with set;
// retrieve them from view state with get.
/** @property 
 */
public String get_Text()
{
    return ((String)(get_ViewState().get_Item("Text")));
} //get_Text

/** @property 
 */
public void set_Text(String value)
{
    get_ViewState().set_Item("Text", value);
} //set_Text

// Add property values to view state with set;
// retrieve them from view state with get.
public function get Text() : String 
{
       return String(ViewState["Text"]);
}

public function set Text(value : String)
{
       ViewState["Text"] = value;
}


Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show: