Add CSS, JS, meta tags to ASP.

Source: Internet
Author: User

ASP. NET background add CSS, JS, meta tags, I write a function here for later use. If the function is placed in a page class, it is also possible to do so by page parameters.

First import namespaces using System.Web.UI.HtmlControls;

        /// <summary>        ///Add JS script link/// </summary>        /// <param name= "page" >page</param>        /// <param name= "url" >Path</param>          Public voidAddjs (System.Web.UI.Page Page,stringURL) {HtmlGenericControl Jscontrol=NewHtmlGenericControl ("Script"); JSCONTROL.ATTRIBUTES.ADD ("type","Text/javascript"); JSCONTROL.ATTRIBUTES.ADD ("src", URL); Page.        HEADER.CONTROLS.ADD (Jscontrol); }        /// <summary>        ///Add JS script content/// </summary>        /// <param name= "page" >page</param>        /// <param name= "Content" >Script Content</param>          Public voidAddscript (System.Web.UI.Page Page,stringcontent) {HtmlGenericControl ScriptControl=NewHtmlGenericControl ("Script"); SCRIPTCONTROL.ATTRIBUTES.ADD ("type","Text/javascript"); Scriptcontrol.innerhtml=content; Page.        HEADER.CONTROLS.ADD (ScriptControl); }        /// <summary>        ///Add CSS style links/// </summary>        /// <param name= "page" >page</param>        /// <param name= "url" >Path</param>          Public voidAddcss (System.Web.UI.Page Page,stringURL) {Htmllink link=NewHtmllink (); 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 voidAddstyle (System.Web.UI.Page Page,stringcontent) {HtmlGenericControl Stylecontrol=NewHtmlGenericControl ("style"); STYLECONTROL.ATTRIBUTES.ADD ("type","Text/css"); Stylecontrol.innerhtml=content; Page.        HEADER.CONTROLS.ADD (Stylecontrol); }        /// <summary>        ///Add META Tags/// </summary>        /// <param name= "page" >page</param>        /// <param name= "name" >meta name</param>        /// <param name= "Content" >meta content</param>          Public voidAddmeta (System.Web.UI.Page Page,stringNamestringcontent) {Htmlmeta meta=NewHtmlmeta (); 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.