ASP. NET

Source: Internet
Author: User

ASP. NET provides a control class: System. Web. UI. HtmlControls. HtmlGenericControl. It can implement an example of HTML elements, such as controlling the <td> element in aspx in. cs code (note that it is not <ASP: TableCell> ). We know that the page TITLE is included in <TITLE> </TITLE>, and <TITLE> is also an HTML element. Therefore, we can use System. web. UI. htmlControls. htmlGenericControl to control <TITLE>.
ASP. NET, if you want. an element in cs that controls aspx (whether it is a Web control or an HTML control), the runat attribute of this element must be set to server, that is, after the runat attribute of the element is set to server. in cs, this element can be controlled (of course, this element must be set to id ).

Now let's try it out. In the HTML code of the aspx file, change the <TITLE> element:
Copy codeThe Code is as follows:
<TITLE runat = "server" id = "titleControl"> Default Title </TITLE>

Be sure to set runat = "server" and id (id is important and case sensitive ). The Default Title is the Default Title. If you do not change the Title, the Default Title is displayed.
Go to the. cs file and declare a variable titleControl. The type is System. Web. UI. HtmlControls. HtmlGenericControl:
Copy codeThe Code is as follows:
Protected System. Web. UI. HtmlControls. HtmlGenericControl titleControl;

In this way, titleControl is <TITLE>. To change the title, add the following content to the. cs method (for example, Page_Load:

TitleControl. InnerText = "I changed the title !";

In fact, for System. web. UI. htmlControls. the HtmlGenericControl control can be used as the performance of all HTML controls on the server, that is, as long as the Code (. aspx. cs /. aspx. vb) declare a System with the same Id as the front-end HTML control. web. UI. htmlControls. you can use the HtmlGenericControl control object, and note that you must add a runat = "server" to the front-end HTML control attribute. Otherwise, background Code does not perform operations on front-end HTML controls.

You can also add the Literal control between <title> </title>. The effect is the same!

Related Article

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.