How to dynamically change the title of an ASP.net page and dynamically specify a page style sheet

Source: Internet
Author: User

To enable the asp.net application to have custom space for users, for example, if you want to use a custom style sheet or title for the page, you can use the following method to dynamically specify it:
First, modify the title and style sheet of the <HEAD> In the ASPX file.
Code generated by Visual Studio:
<Title> WebForm1 </Title>
<LINK ref = "stylesheet" type = "text/css" href = "control.css">
Modified code:
<Title runat = "server" id = "Title1"> WebForm1 </title>
<LINK id = "link1" runat = "server" type = text/css "ref =" stylesheet "> </link>
We add runat = server to both HTML elements and mark them as server-side controls so that we can access them in the server code.

In the WebForm1.aspx. cs file, we can use the C # code to control the row.
Private void button#click (object sender, System. EventArgs e)
{
Control ctrl = Page. FindControl ("Title1"); // search for the Title we modified to runat = server.
(HtmlGenericControl) ctrl). InnerText = "Hello ";
Ctrl = Page. FindControl ("link1 ");
(HtmlGenericControl) ctrl). Attributes. Add ("href", "control.css ");

}

The above steps can be used to dynamically change the title of the ASP.net page and dynamically specify the page style table.

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.