Adding HTML Server Controls to a Web Forms Page
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
- From the HTML tab of the Toolbox, drag an HTML element onto the page.
- 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 () 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
- Switch to HTML view.
- 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.
<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.
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