How to: Add HTML Server Controls to a Web Page Using ASP.NET Syntax

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 information about controls for ASP.NET Web pages, see ASP.NET Web Server Controls Overview.

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

To add an HTML server control

  • 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 GridView controls).

    • Set the runat="server" attribute to convert the element to a control.

    The following example shows how to declare an HtmlInputText control, 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. 
    
    <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, see HTML Server Controls.

See Also

Tasks

How to: Convert HTML Server Controls to HTML Elements

How to: Set HTML Server Control Properties Programmatically