Include .css files in asp.net

Since the virturl directory name is not fixed, I wrote the code below to include the .css file on the .aspx page.

<link rel="Stylesheet" href="<%= ResolveUrl("~/Css/xxx.css") %>" type="text/css" /> 

The question is, when I use "ResolveUrl" in the tag, the IDE always barks that all CSS classes are undefined.

Is there a better way to identify a .css file containing?

+6
css visual-studio
source share
3 answers

You can do this using the html server controls (note the runat="server" ) as follows:

 <link rel="stylesheet" runat="server" media="screen" href="~/css/styles.css" /> 

It will still allow you a virtual directory. It should also support css intellisense and warnings on an aspx page.

+17
source share

You can include files statically inside <% if (false) { %> .

Thus, Visual Studio IntelliSense will see the files, but ASP.Net runtime will not.
(And the if (false) block should be optimized by the compiler, so there should be a zero performance hit)

+3
source share

The IDE will not know that you are including this css file, simply because it will be generated at run time, and not earlier.

If you need intelisense to put it manually and change it later when you need it.

0
source share

All Articles