Export (0) Print
Expand All

Server-Side Object Tag Syntax

Declares and creates COM and .NET objects in a Web Forms page.

<object id="id" runat=server latebinding=true|false class=".NET Framework Class Name">
<object id="id" runat=server latebinding=true|false progid="COM ProgID"/>
<object id="id" runat=server latebinding=true|false classid="COM ClassID"/>

Attributes

id
Unique name to use when referencing the object in subsequent code.
class
Specifies the .NET Framework class to create.
progID
Specifies the COM component to create by specifying the component's programmatic identifier.
classID
Specifies the COM component to create using the component's class identifier.
latebinding
Indicates whether late-binding APIs should be used with COM components that have been processed by the Type Library Importer (Tlbimp.exe). true indicates that late-binding APIs should be used; false indicates that early-binding APIs should be used. The default is false.

Remarks

When the ASP.NET page parser encounters a server-side object tag in an .aspx file, it generates a read-only property on the page, using the id attribute of the tag as the property name. The read property is then configured to create an instance of the object on first use. The resulting instance is not added as an object within the page's hierarchical server control tree; it is instead treated as a non-UI variable declaration.

The classid, progid, and class attributes are mutually exclusive. You cannot include more than one of these attributes in a single server-side object tag. You can, however, include multiple server-side object tags on a Web Forms page and use these attributes in different tags.

Example

The following example uses server-side object syntax to create an instance of the ArrayList .NET Framework class in a Web Forms page.

<html>
   <object id="items" class="System.Collections.ArrayList" runat=server/>
   <script language="C#" runat=server>
      void Page_Load(Object sender, EventArgs e) {
         items.Add("One");
         items.Add("Two");
         items.Add("Three");

         MyList.DataSource = items;
         MyList.DataBind();
      }
   </script>

   <body>
      <asp:datalist id="MyList" runat=server>
         <ItemTemplate>
            Here is a value: <%# Container.DataItem %>
         </ItemTemplate>
      </asp:datalist>
   </body>
</html>
[Visual Basic]
<html>
   <object id="items" class="System.Collections.ArrayList" runat=server/>
   <script language="VB" runat=server>
      Sub Page_Load(Sender As Object, E As EventArgs)
         items.Add("One")
         items.Add("Two")
         items.Add("Three")

         MyList.DataSource = items
         MyList.DataBind()
      End Sub
   </script>

   <body>
      <asp:datalist id="MyList" runat=server>
         <ItemTemplate>
            Here is a value: <%# Container.DataItem %>
         </ItemTemplate>
      </asp:datalist>
   </body>
</html>

See Also

Introduction to Web Forms Pages | ASP.NET Web Forms Syntax

Show:
© 2014 Microsoft