How to make user controls know about css classes in ASP.NET

Here’s what I did:

<link rel="Stylesheet" type="text/css" href="https://stackoverflow.com/questions/34390/Stylesheet.css" id="style" runat="server" visible="false" />

It fools Visual Studio into thinking you’ve added a stylesheet to the page but it doesn’t get rendered.


Here’s an even more concise way to do this with multiple references;

<% if (false) { %>
    <link rel="Stylesheet" type="text/css" href="https://stackoverflow.com/questions/34390/Stylesheet.css" />
    <script type="text/javascript" src="js/jquery-1.2.6.js" />
<% } %>

As seen in this blog post from Phil Haack.

Leave a Comment