css style sheet from content page

ぃ、小莉子 提交于 2019-12-11 12:25:54

问题


Iv'e got a content page with a link to a style sheet which I want to be specific for that page , i.e. I want the design to be specific for that page when it loads and takes its place in the contentplaceholder on the main page.

IN MY CONTENT PAGE :

  <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">  
      <link href="~/Styles/StyleSheet1.css" rel="stylesheet" type="text/css" />
  </asp:Content>

IN MY MAIN PAGE :

   <asp:ContentPlaceHolder ID="head" runat="server">       
   </asp:ContentPlaceHolder>  

MY STYLE SHEET ~/Styles/StyleSheet1.css just for example I'll give this id to some table in my content page.

       #defualt_tbl
       {
          background-color:Gray;
       }

       <table id="defualt_tbl">

The table does not become gray , when I click viewsource in the master page the link is present in the head section.

        <link href="~/Styles/StyleSheet1.css" rel="stylesheet" type="text/css" />

回答1:


You can only use the ~ root specifier in server controls, the browser doesn't understand that URL, and doesn't know where your application root is either even if it would.

Put runat="server" in the link tag, or use an URL that is relative to the site root:

<link href="/Styles/StyleSheet1.css" rel="stylesheet" type="text/css" />



回答2:


I'm not sure you can use the tilda ~ for the path in the link. I think the tilda(~) is a .net shortcut, and since your just rendering html the browser won;t know where to look.




回答3:


found it !

but i belive your answers work as well .

  <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
     <link href='<%= ResolveClientUrl("~/Styles/StyleSheet1.css") %>' rel="stylesheet"    type="text/css" />
  </asp:Content>


来源:https://stackoverflow.com/questions/7431694/css-style-sheet-from-content-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!