开发者

Include .css files in asp.net

开发者 https://www.devze.com 2023-01-08 03:05 出处:网络
Since virturl directory name is not fixed, I wrote code below to include .css file in .aspx page now.

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

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

The question is, when I use "ResolveUrl" in tag, IDE is always barki开发者_运维百科ng about that all CSS classes is undefined.

Is there any better way to define .css file including?


You can do this with html server controls (notice the runat="server") like so:

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

This will still resolve the virtual directory for you. It should also support the css intellisense and warnings on the aspx page.


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

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


The IDE will not know that you are including that css file, simply because it will generate in runtime, not before it.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消