Wednesday, February 03, 2010

HtmlLink control to programmatically add a Stylesheet to a Web Page

Source Where I found following code

  protected void Page_Init(object sender, EventArgs e)
  {
    // Define an HtmlLink control.
    HtmlLink myHtmlLink = new HtmlLink();
    myHtmlLink.Href = "~/StyleSheet.css";
    myHtmlLink.Attributes.Add("rel", "stylesheet");
    myHtmlLink.Attributes.Add("type", "text/css");
    
    // Add the HtmlLink to the Head section of the page.
    Page.Header.Controls.Add(myHtmlLink);
    
  }