AddCSS

public static void AddCSS(this Page page, string url)
{
    HtmlLink link = new HtmlLink();
    link.Href = url;
    link.Attributes["rel"] = "stylesheet";
    link.Attributes["type"] = "text/css";
    page.Header.Controls.Add(link);
}
Example:
public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.AddCSS("cssFile.css");
    }
}

Description

Dynamically adds a cascading style sheet (a.k.a. CSS) file to a page even if using master page.

Details

Double click on the code to select all.

 

;