How to make user controls know about css classes in ASP.NET

后端 未结 4 576
青春惊慌失措
青春惊慌失措 2020-11-28 22:10

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 rec

相关标签:
4条回答
  • 2020-11-28 22:21

    Here's what I did:

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

    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" />
    <% } %>
    

    As seen in this blog post from Phil Haack.

    0 讨论(0)
  • 2020-11-28 22:23

    If you are creating composite UserControl, then you can set the CSSClass property on the child controls..

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

    0 讨论(0)
  • 2020-11-28 22:24

    Add the style on your usercontrol and import css in 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 
    
    0 讨论(0)
  • 2020-11-28 22:25

    You Can use CSS direct 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's height */ 
           }
        </style>
     </head>
    

    This will work.

    0 讨论(0)
提交回复
热议问题