Name

Item

Synopsis

Object = Application.Item(ByVal name As String)
Application.Item(ByVal name As String) = Object
Object = Application.Item(ByVal index As Integer)
Application.Item(ByVal index As Integer) = Object

Returns or sets an Object associated with a particular name or index.

Parameters

Object

A variable of any type (since all .NET types are ultimately derived from Object) that will receive or set the item’s value.

name

A String argument containing the text key to apply to the item (or by which to retrieve the item).

index

An Integer argument containing the index of the item whose value will be retrieved or modified.

Example

The example sets the values of two items in the Application collection. If these items do not already exist in the collection, they will be added. The example then displays the two values.

Sub Page_Load(  )
   Application.Clear(  )
   Application.Item("foo") = "foo"
   Application.Item("foo2") = "foo2"
   Message.Text = Application.Item("foo") & "<br/>"
   Message.Text &= Application.Item(1)
End Sub

Notes

The Item property is accessed implicitly when using the syntax:

Application("foo") = "foo"

This syntax is often seen in classic ASP code. Explicitly referencing the Item property is not required, but listing it may make your code more readable and understandable than accessing it implicitly.

Note that an index may only be used as an argument when modifying a value, not when creating a new item, and the index must be less than the number of items in the Application collection, ...

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.