如何让用户控件了解 ASP.NET 中的 css 类 [英] How to make user controls know about css classes in ASP.NET

查看:15
本文介绍了如何让用户控件了解 ASP.NET 中的 css 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于asp.net 中没有用户控件的标题部分,因此用户控件无法了解样式表文件.因此,visual studio 无法识别用户控件中的 css 类并产生警告.如何让用户控件知道它将与 css 类相关,因此如果它警告我不存在的 css 类,则表示该类确实不存在?

Since there are no header sections for user controls in asp.net, user controls have no way of knowing about stylesheet files. So css classes in the user controls are not recognized by visual studio and produces warnings. How can I make a user control know that it will relate to a css class, so if it is warning me about a non-existing css class, it means that the class really do not exist?

或者我应该采用不同的设计,例如将 css 类公开为 GridView 的HeaderStyle-CssClass"等属性?

Or should I go for a different design like exposing css classes as properties like "HeaderStyle-CssClass" of GridView?

推荐答案

这是我所做的:

<link rel="Stylesheet" type="text/css" href="Stylesheet.css" id="style" runat="server" visible="false" />

它使 Visual Studio 误以为您已向页面添加了样式表,但它没有被呈现.

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="Stylesheet.css" />
    <script type="text/javascript" src="js/jquery-1.2.6.js" />
<% } %>

这篇博文来自 Phil Haack.

As seen in this blog post from Phil Haack.

这篇关于如何让用户控件了解 ASP.NET 中的 css 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆