如何让用户控件了解ASP.NET中的css类

由于asp.net中没有用户控件的标题部分,用户控件无法了解样式表文件。 因此用户控件中的css类不被visual studio识别并产生警告。 我怎样才能让一个用户控件知道它将涉及到一个CSS类,所以如果它警告我一个不存在的CSS类,这意味着该类真的不存在?

编辑:或者我应该去一个不同的devise,如暴露的CSS类为像GridView的“HeaderStyle-CssClass”的属性?

以下是我所做的:

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

它愚弄Visual Studio认为你已经添加了一个样式表到页面,但它不会被渲染。


这里有一个更简洁的方法来做到这一点与多个引用;

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

从Phil Haack的博客文章中可以看出。

如果您正在创build复合UserControl,则可以在子控件上设置CSSClass属性。

如果不是的话,那么你需要暴露属于Styletypes的属性,或者(在我经常这样做的情况下)在呈现types中应用CSS的string属性(即,在呈现时将其属性添加到HTML标记中并添加样式属性) 。

在你的usercontrol中添加样式并在其中导入css。

  <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="WCReportCalendar.ascx.vb" Inherits="Intra.WCReportCalender" %> <style type='text/css'> @import url("path of file.css"); // This is how i used jqueryui css @import url("ui/1.10.0/themes/base/jquery-ui.css"); </style> your html 

你可以直接在userControl使用CSS

UserControl使用这个:

  <head> <title></title> <style type="text/css"> .wrapper { margin: 0 auto -142px; /* the bottom margin is the negative value of the footer's height */ } </style> </head> 

这将工作。