This documentation is archived and is not being maintained.

Adding HTML Server Controls to a Web Forms Page

Visual Studio .NET 2003

Adding HTML server controls is like adding any HTML element, except that you convert the element to a control so that you can work with it in server code.

Note   For background information about controls for Web Forms pages, see Introduction to ASP.NET Server Controls.

Adding HTML Server Controls Using the Web Forms Designer

Adding HTML server controls to a Web Forms page is a two-step process.

To add an HTML server control to a Web Forms page

  1. From the HTML tab of the Toolbox, drag an HTML element onto the page.
  2. Convert the element to a control by right-clicking it and choosing Run As Server Control.

    The Web Forms Designer adds the attribute runat="server" to the element, which alerts the server to treat the element as a control. A glyph (17x94dy9.vbwebformsservercontrolglyph(en-us,VS.71).gif) appears on the control in Design view to indicate that it is a server-based control.

    Note   By default, the Web Forms page uses Grid layout, and you place controls at absolute positions on the page (using x and y coordinates). If you want to use linear layout, in which the page elements flow as in a word processing document, you can change the page's pageLayout property, or include a Flow Layout Panel HTML server control. For more details, see Positioning HTML Elements in Design View.

Adding HTML Server Controls using ASP.NET Syntax

You can add an HTML server control to a page by declaring it directly in the .aspx file.

To add an HTML server control using ASP.NET syntax

  1. Switch to HTML view.
  2. Type the HTML syntax of the element you want to use as a control. Include the normal HTML syntax for the element, and in addition, do the following:
    • Set the control's ID attribute (property) to a unique value for that page, unless the control is part of a complex control and will be repeated (as in Repeater, DataList, and DataGrid controls).
    • Set the runat="server" attribute to convert the element to a control.

    The following example shows how to declare an HtmlInputText control, an HtmlInputButton control, and an HtmlAnchor control:

    <input id="Name" type=text size=40 runat="server">
    <input type=submit id="Enter" value="Enter" runat="server">
    Click <a id="Anchor1" runat="server" href="more.html">More </a> to see the next page. 

For information about the declarative syntax for a specific HTML server control, search in the Index in Help for "HTML server controls" and choose name of the control you want to use.

See Also

ASP.NET Server Controls | Adding Controls to a Web Forms Page Programmatically | Adding Web Server Controls to a Web Forms Page | Converting HTML Server Controls to HTML Elements | Creating Event Handlers in Web Forms Pages | Setting HTML Server Control Properties Programmatically | Web Forms Validation | Referencing Controls in Web Forms Pages