Dynamically introduce JS files and CSS style sheet files

Source: Internet
Author: User
When developing a web project, you will always encounter many relationships between user controls. ascx and pages, or between pages and master pages. Use a partial page

It is better to dynamically introduce JS files or style sheet files to the master page, or dynamically introduce JS files and style sheets as needed in the user control.

Here is a method I introduced:
// Introduce the JS File
Htmlgenericcontrol scriptcontrol = new htmlgenericcontrol ("script ");
Scriptcontrol. Attributes. Add ("type", "text/JavaScript ");
Scriptcontrol. Attributes. Add ("language", "JavaScript ");
Scriptcontrol. Attributes. Add ("src", "http://images.dayoo.com/travel/9208.files/changeimg.js ");
Page. header. Controls. Add (scriptcontrol );
// Introduce the style sheet
Literal csscontrol = new literal ();
Csscontrol. Text = "<link href = \" http://images.dayoo.com/photo/17358.files/css.css\ "rel = \" stylesheet \ "type = \" text/CSS \ "/> ";
Page. header. Controls. Add (csscontrol );

the preceding Code is displayed in the page or control pageload.

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.