如何使用户控件知道在ASP.NET中的CSS类 [英] How to make user controls know about css classes in ASP.NET

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

问题描述

由于在asp.net中没有用户控件的标题部分,用户控件无法知道样式表文件。因此,用户控件中的css类不被visual studio识别,并产生警告。我如何让一个用户控件知道它将与一个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的此博文

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

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