ASP.NET Syntax Global.asax Syntax
Declare and create new application and session variables using a declarative, tag-based syntax.
<object id="id" runat=server class = "Class Name">
<object id="id" runat=server progid="COM ProgID" />
<object id="id" runat=server classid="COM ClassID" />
- id
- A unique name to use when referencing the object in subsequent code.
- Class Name
- The class to create a new instance of.
- COM ProgID
- The COM component to create a new instance of.
- COM ClassID
- The COM component to create a new instance of.
The <object
> tag supports the following attributes:
ID |
Provides a unique identifier to use when declaring an object on the page. |
Runat |
Must be set to "server" for the object to execute within ASP.NET. All non-server values cause the page compiler to assume that the object tag should be transmitted down for a client to handle. |
Scope |
Declares the scope at which the object is declared. "Pipeline" indicates that the object is available only to the HttpPipeline instance defined by the containing ASP.NET application file. "Application" indicates that the object is populated into the HttpApplicationState collection. "Session" indicates that the object is populated into session state. If no scope is specified, scope defaults to "Pipeline". |
Class |
Identifies the object type to create a new instance of. |
ProgID |
Identifies COM component to create a new instance of. |
ClassID |
Identifies COM component to create a new instance of. |
When the ASP.NET processor encounters a server-side object tag in an ASP.NET application file, it generates a get/set property on the class, using the ID attribute of the tag as the property name. The get method is then configured to create an instance of the object on first use.
If the object tag’s scope attribute is set to either "Application" or "Session", a reference to the object ( or at least enough information to lazily create it the first time it is accessed ) is added to the StaticObjects collection of the appropriate application or session object. The object is automatically added to the namespace of all .aspx pages within the application.
The classid
, progid
, and class
attributes are mutually exclusive. It is an error to use more than one of these attributes within a single server-side object tag.
The below code snippet demonstrates how to use the <Object> element to create an ArrayList object on a Web Forms page. You can then programmatically access the object by using its items ID.
<object id="items" class = "System.Collections.ArrayList" runat="server" />
ASP.NET Applications