asp.net background to add CSS, JS, Meta tags method _ practical skills

Source: Internet
Author: User

The following is from the asp.net background to add CSS, JS, meta tags of the writing, we write here to facilitate the use of functions. If the function is placed in the page class, the page parameter is also not available.
First, the namespace using System.Web.UI.HtmlControls is imported;

Copy Code code as follows:

///
Add JS Script link
///
Page
Path
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);
}


///
Add JS script content
///
Page
Script Content
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);
}


///
Add CSS style Links
///
Page
Path
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);
}


///
Add CSS style content
///
Page
Style content
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);
}


///
Add META Tags
///
Page
Meta name
Meta content
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.