ASP. NET-use ASP. NET web server controls (2)

Source: Internet
Author: User

 

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.