2. Add HTML server controls to ASP. NET web pages
The HTML server control is an HTML element that you can configure to use server code to program it.
1. How to: use ASP. NET syntax to add HTML server controls to webpages
Adding an HTML Server Control is similar to adding any HTML element. The difference is that you need to convert the element into a control so that it can be used in the server code. the aspx file directly declares the HTML Server Control to add this control to the page.
Add HTML server controls
· Type the HTML syntax of the element to be used as the control. General HTML syntax containing this element. perform the following operations:
· Unless the control is an integral part of a complex control and will appear repeatedly (for example, in the repeater, datalist, and gridview controls ), otherwise, set the ID attribute of the control to a unique value for the page.
· Set the runat = "server" attribute to convert elements into controls.
The following example demonstrates how to declare the htmlinputtext control, htmlinputtext control, htmlinputbutton control, and 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.
2. How to: convert HTML server controls to HTML elements
If you no longer need to program HTML server controls in server code, convert them to pure HTML elements. Every HTML Server Control in the page uses resources, so it is best to minimize the number of controls required for ASP. NET web pages.
Convert HTML server controls to HTML elements
· Remove the runat = "server" attribute from the control tag.
· You do not have to remove the ID attribute. If there is a client script that references this element, be careful not to remove the ID attribute.