Add a stylesheet link programmatically in ASP.NET

Code snippet for programmatically adding a CSS link in ASP.NET.

  • 6 September 2010
  • 0

Here’s a code snippet used to programmatically insert a stylesheet link to an external CSS file:

// Create the <link> element for the CSS file
var stylesheet = new HtmlLink { Href = "/path/to/stylesheet.css" };
// Add it to the <head> element of the page