How to make user controls aware of CSS classes in ASP.NET

Because asp.net does not have header sections for user controls, user controls are not able to learn about style files. Thus, the css classes in user controls are not recognized by the visual studio and do not cause a warning. How can I make the user control know that it will belong to the css class, so if it warns me of a non-existent css class, does this mean that the class really does not exist?

Edit: Or do I need to use a different design, for example, exposing css classes as properties such as the "HeaderStyle-CssClass" GridView?

+49
css visual-studio-2008 user-controls
Aug 29 '08 at 11:37
source share
4 answers

Here is what I did:

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

It tricks Visual Studio into thinking that you added a stylesheet to the page, but it doesn’t appear.




Here's an even shorter way to do this with a few links;

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

As you can see from this blog post by Phil Haack.

+63
Aug 29 '08 at 15:52
source share

Add a style to your usercontrol and import css into it.

  <%@ 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("http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css"); </style> your html 
+1
Feb 08 '13 at 14:42
source share

If you create a composite UserControl, you can set the CSSClass property to child controls.

If not, then you need to set properties that are either Style types or (as I often do) string properties that apply CSS to the rendering type (i.e. take their properties and add the style attribute to the HTML tags when rendering) .

0
Aug 29 '08 at 15:03
source share

You can use CSS directly in userControl .

Use this in userControl :

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

This will work.

-four
Mar 31 2018-12-12T00:
source share



All Articles