Add CSS, JS, and Meta tags to the Asp.net background

Source: Internet
Author: User

Add CSS, JS, and Meta labels to the Asp.net background. I will write functions here for future use. If a function is placed in a Page class, the Page parameter is optional.

First, import the namespace using System. Web. UI. HtmlControls;

/// <Summary> /// Add the JS script link /// </summary> /// <param name = "page"> page </param> /// <param name = "url"> path </param> public void AddJS (System. web. UI. page page, string url) {HtmlGenericControl jsControl = new HtmlGenericControl ("script"); jsControl. attributes. add ("type", "text/javascript"); jsControl. attributes. add ("src", url); page. header. controls. add (jsControl );} /// <summary> /// Add the JS script content /// </summary> /// <param name = "page"> page </param> /// <param name = "content"> script content </param> public void AddScript (System. web. UI. page page, string content) {HtmlGenericControl scriptControl = new HtmlGenericControl ("script"); scriptControl. attributes. add ("type", "text/javascript"); scriptControl. innerHtml = content; page. header. controls. add (scriptControl );} /// <summary> /// Add a CSS style link /// </summary> /// <param name = "page"> page </param> /// <param name = "url"> path </param> public void AddCss (System. web. UI. page page, string url) {HtmlLink link = new HtmlLink (); link. href = url; link. attributes. add ("rel", "stylesheet"); link. attributes. add ("type", "text/css"); page. header. controls. add (link );} /// <summary> /// add CSS style content /// </summary> /// <param name = "page"> page </param> /// <param name = "content"> style content </param> public void AddStyle (System. web. UI. page page, string content) {HtmlGenericControl styleControl = new HtmlGenericControl ("style"); styleControl. attributes. add ("type", "text/css"); styleControl. innerHtml = content; page. header. controls. add (styleControl );} /// <summary> /// add Meta tag /// </summary> /// <param name = "page"> page </param> /// <param name = "name"> Meta name </param> // <param name = "content"> Meta content </param> public void AddMeta (System. web. UI. page page, string name, string content) {HtmlMeta meta = new HtmlMeta (); meta. name = name; meta. content = content; page. header. controls. add (meta );}

 

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.