ASP. NET dynamically adds CSS style JS title keywords to the front end, cssjs

Source: Internet
Author: User

ASP. NET dynamically adds CSS style JS title keywords to the front end, cssjs

Many website readers can change their favorite styles. Some websites want to share backend code with multiple sites and only change the front-end styles. They can dynamically replace CSS styles and JS styles. For webform development, you can use the following methods:

The process is to first read data from the data or xml, and then assign the value to the front-end page

HTML <meta> label Addition

HtmlMeta mtdes = new HtmlMeta (); // create an instance

Mtdes. Name = "Description"; // tag

Mtdes. Content = this. Descriptionp; // Content

Header. Controls. Add (mtdes); Add css attributes

 

HTML <Link> label addition, which is the key to dynamically adding CSS styles

HtmlLink hlk = new HtmlLink (); // create an instance

Hlk. Href = "css/a.css"; // Add a css address

Hlk. Attributes. Add ("rel", "stylesheet"); // Add css Attributes

Hlk. Attributes. Add ("type", "text/css"); // Add css Attributes

Header. Controls. Add (hlk); // Add it to the page Header Control

The following is the same:

HtmlLink csslink2 = new HtmlLink ();

Csslink2.Href = "css/css1.css ";

Csslink2.Attributes. Add ("rel", "stylesheet ");

Csslink2.Attributes. Add ("type", "text/css ");

Header. Controls. Add (csslink2 );

 

Add JS dynamically

HtmlGenericControl jslink = new HtmlGenericControl ("script"); Create a script instance

Jslink. Attributes ["type"] = "text/javascript"; // indicates the js text category.

Jslink. Attributes ["src"] = "js/elf. js"; // URL of JS

Header. Controls. Add (jslink); // Add it to the page Header Control

 

Add title and description

This. Titlep = dr ["title"]. ToString ();

This. Descriptionp = dr ["breif"]. ToString ();

This. Label3.Text = dr ["title"]. ToString ();

This. Label4.Text = dr ["About"]. ToString ();

Page. Title = Titlep; Add Title method 2

In fact, there are many methods. You can expand your ideas and implement them in other ways.

If any of the above articles is correct

 

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.