Name
StaticObjects
Synopsis
HttpStaticObjectsCollection = Session.StaticObjects
Returns an HttpStaticObjectsCollection containing all objects
instantiated in global.asax by using the
<object runat="server"> syntax whose scope
is set to Session.
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="session" runat="server"/>
syntax in global.asax. It then checks the type
of each object and, if it is a TextBox web control, adds it to the
Controls collection of the form:
Sub Page_Load( )
Message.Text = "There are " & Session.StaticObjects.Count & _
" objects declared with the " & _
"<object runat="server"> syntax in Session scope."
Dim myobj As Object
For Each myObj in Session.StaticObjects
If myObj.Value.GetType.ToString( ) = _
"System.Web.UI.WebControls.TextBox" Then
myForm.Controls.Add(myObj.Value)
End If
Next
End SubYou also need to modify the <body> section of the document as follows:
<body>
<form id="myForm" runat="server">
<asp:label id="Message" runat="server"/>
</form>
</body>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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access