Add CSS, JS, meta tags to ASP.

Source: Internet
Author: User
Here is the addition of CSS, JS, meta tags from the ASP, we 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 links///</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 JS script content///</summary>//<param name= "page" > pages </pa ram>//<param name= "Content" > Script content </param> public void Addscript (System.Web.UI.Page page, s                Tring content) {HtmlGenericControl ScriptControl = new HtmlGenericControl ("script");                SCRIPTCONTROL.ATTRIBUTES.ADD ("type", "Text/javascript");                scriptcontrol.innerhtml = content; Page. Header.cOntrols.        ADD (ScriptControl); }///<summary>///Add CSS style links///</summary>//<param name= "page" > pages </p aram>//<param name= "url" > Path </param> public void Addcss (System.Web.UI.Page Page, string ur                L) {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" > pages </p aram>//<param name= "content" > Style content </param> public void Addstyle (System.Web.UI.Page page, s                Tring content) {HtmlGenericControl Stylecontrol = new HtmlGenericControl ("style");                STYLECONTROL.ATTRIBUTES.ADD ("type", "text/css"); stylecontrol.innerhtml = content;               Page.        HEADER.CONTROLS.ADD (Stylecontrol); }///<summary>///Add META tags///</summary>//<param name= "page" > pages </pa ram>//<param name= "name" >meta name </param>///<param name= "content" >meta contents &LT;/PARAM&G         T public void Addmeta (System.Web.UI.Page Page, string name, string content) {Htmlmeta meta = new Html                Meta (); Meta.                name = name; Meta.                Content = content; Page.        HEADER.CONTROLS.ADD (meta); }
  • 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.