Asp. NET to the front-end dynamic add modify CSS style JS title keyword

Source: Internet
Author: User

There are many web site readers can change their favorite style, and some sites want to multi-site sharing back-end code and only move the former paragraph style, you can use the dynamic replacement of CSS style and JS. If you are developing WebForm, you can use the following methods:

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

HTML <meta> Tag Additions

Htmlmeta mtdes = new Htmlmeta ();//new instance

Mtdes. Name = "Description";//Label

Mtdes. Content = this. descriptionp;//Content

HEADER.CONTROLS.ADD (mtdes); adding CSS Properties

HTML <Link> tag Additions, which is the key to dynamically adding CSS styles

Htmllink hlk = new Htmllink ();//new instance

Hlk. Href = "CSS/A.CSS";//Add CSS Address

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

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

HEADER.CONTROLS.ADD (HLK);//Add to the page header control

Same as below:

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 new script instance

Jslink. attributes["type"] = "text/javascript";//Mark JS text category

Jslink. attributes["src"] = "js/elf.js";//js's URL address

HEADER.CONTROLS.ADD (Jslink); Add to 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 heading Mode 2

In fact, there are a lot of methods, we can expand their thinking in other ways to achieve.

If you have any questions about the above article, please treatise

Asp. NET to the front-end dynamic add modify CSS style JS title keyword

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.