asp.net.ph

Skip Navigation Links

Adding HTML Server Controls to a Web Forms Page

ASP.NET Web Forms   Web Forms Server Controls   Programming Web Forms Server Controls


Adding HTML server controls to a Web Forms page is like adding any HTML element, except that you convert the element to a control that you can work with in server code. You can add an HTML server control by declaring it directly in the .aspx file.

NOTE: For background information on ASP.NET HTML controls, see Introduction to Web Forms Server Controls.

To add an HTML server control

Type the HTML syntax of the element you want to use as a control. Include the standard HTML syntax for the element, and in addition, do the following:

  • Set the runat="server" attribute to convert the element to a control.
  • Set the control’s id attribute 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 ).

The following example shows how to declare standard HTML form input elements as server controls on a Web Forms page.

htmlformcontrols.aspx
Run Sample | View Source

For information about the declarative syntax for a specific control, see ASP.NET Syntax for HTML Controls.

IMPORTANT: Unless you need to program an HTML form element in server code, you should just leave it as a plain HTML element. Each HTML server control in a form uses server resources, so it is always good practice to use only server controls that the Web Forms page has to work with.

To convert an HTML server control to an HTML element

  • Remove the runat="server" attribute from the control’s tag.

You do not have to remove the id attribute, especially if there is client script that references the element.

See Also

Adding Controls to a Web Forms Page Programmatically   Adding Web Server Controls to a Web Forms Page   Setting HTML Server Control Properties Programmatically   Web Forms Validation



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note