Compartilhar via


Server-Side Object Tag Syntax 

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

<object id="id" 
        runat="server" 
        latebinding="true|false" 
        class="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

  • class
    Specifies the .NET Framework class to create.
  • classID
    Specifies the COM component to create using the component's class identifier.
  • id
    Unique name to use when referencing the object in subsequent code.
  • 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.
  • progID
    Specifies the COM component to create by specifying the component's programmatic identifier.
  • 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 sent to the client to handle.

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-only 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-user interface (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.

NoteNote

For security reasons, managed controls using the <object> tag and file access protocol in an HTML page are not supported. Therefore, you cannot reference files directly from within the tag.

Example

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

<%@Page language="C#" %>
<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>
      <form id="form1" runat="server">
      <asp:datalist id="MyList" runat=server>
         <ItemTemplate>
            Here is a value: <%# Container.DataItem %>
         </ItemTemplate>
      </asp:datalist>
      </form1>
   </body>
</html>
<%@Page language="VB" %>
<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>
      <form id="form1" runat="server">
      <asp:datalist id="MyList" runat=server>
         <ItemTemplate>
            Here is a value: <%# Container.DataItem %>
         </ItemTemplate>
      </asp:datalist>
      </form1>
   </body>
</html>

See Also

Concepts

ASP.NET Web Page Syntax Overview
Introduction to ASP.NET Web Pages