Name

StaticObjects

Synopsis

HttpStaticObjectsCollection = Application.StaticObjects

Returns an HttpStaticObjectsCollection containing all objects instantiated in global.asax using the <object runat="server"> syntax whose scope attribute is set to Application.

Parameters

HttpStaticObjectsCollection

A variable of type HttpStaticObjectsCollection that will receive the StaticObjects property value.

Example

The example uses the Count property of the HttpStaticObjectsCollection class to display the number of objects in the current application declared with the <object scope="Application" runat="server"/> syntax in global.asax. It then checks the type of each object, and if it is a Web TextBox control, adds it to the Controls collection of the current page.

Sub Page_Load(  )
   Message.Text = "There are " & Application.StaticObjects.Count & _
      " objects declared with the " & _
      "&lt;object runat=&quot;server&quot;&gt; syntax " & _ 
      "in Application scope."
   Dim myobj As Object
   For Each myObj in Application.StaticObjects
      If myObj.Value.GetType.ToString(  ) = _
         "System.Web.UI.WebControls.TextBox" Then
         Page.Controls.Add(myObj.Value)
      End If
   Next
End Sub

Notes

This property is provided for backward compatibility with classic ASP. You should think carefully before instantiating objects with Session or Application scope because of the impact such objects have on resource usage and application scalability. In most cases, it is advisable to limit objects to page scope.

Note that each object in the 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.