Cant apply style to page

Last post 02-14-2008 5:17 AM by Amanda Wang - MSFT. 5 replies.

Sort Posts:

  • Cant apply style to page

    02-12-2008, 11:19 AM
    • Loading...
    • razamit
    • Joined on 05-24-2006, 7:18 AM
    • Posts 21

    Hi

    I have an application with one master page and afew content pages. i implemented a css file with styles for Labels and such and linked it in the master page.

    the problem is that on all pages it workes fine except on one page where the style simple wont apply

    does anyone have an idea?

    Filed under: , ,
  • Re: Cant apply style to page

    02-12-2008, 11:29 AM
    • Loading...
    • mcmcomasp
    • Joined on 03-08-2004, 4:45 PM
    • Toronto
    • Posts 1,357

    can we see the link to the style sheet your trying to apply to that does not work?

    mcm

  • Re: Cant apply style to page

    02-12-2008, 11:35 AM
    • Loading...
    • razamit
    • Joined on 05-24-2006, 7:18 AM
    • Posts 21

    the master page code is here:

     

    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage.master.cs"
        Inherits="test.MasterPage" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>test</title>
        <link href="GeneralStyles.css" rel="stylesheet" type="text/css" />
    </head>
    <body style="background: #000000">
        <form id="form1" runat="server" style="margin-top: 50px">
        <center>
            <div>
                <asp:Panel runat="server" Width="1024" Height="200" BackImageUrl="~/Images/PanelBackgroundImages/H2.png">
                    <asp:Menu ID="MainMenu" runat="server" Orientation="Horizontal" Style="margin-left: 620px;
                        margin-top: 175px;" DynamicHorizontalOffset="5" Font-Names="Verdana" Font-Size="12"
                        Font-Bold="true" ForeColor="#faaa05" StaticSubMenuIndent="10px">
                        <StaticSelectedStyle BackColor="#507CD1" />
                        <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                        <DynamicHoverStyle BackColor="#faaa05" ForeColor="Black" />
                        <DynamicMenuStyle BackColor="#B5C7DE" />
                        <DynamicSelectedStyle BackColor="#507CD1" />
                        <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                        <StaticHoverStyle BackColor="#faaa05" ForeColor="Black" />
                        <Items>
                        </Items>
                    </asp:Menu>
                </asp:Panel>
                <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                </asp:ContentPlaceHolder>
            </div>
        </center>
        </form>
    </body>
    </html>
    
     

     and the page is this

    <%@ Page Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true"
        CodeBehind="WebForm1.aspx.cs" Inherits="test.WebForm1" Title="Untitled Page" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <script src="../Scripts/PostPage.js" type="text/javascript"></script>
    
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        </asp:ScriptManager>
        <asp:Panel runat="server" ID="m_testPanel" Width="584">
        </asp:Panel>
    </asp:Content>
     

     

  • Re: Cant apply style to page

    02-12-2008, 2:02 PM
    • Loading...
    • mcmcomasp
    • Joined on 03-08-2004, 4:45 PM
    • Toronto
    • Posts 1,357

    is the content page nested in a level that is not the same as the other, working pages?

    if it is in another level you can just override the style link and by putting a new style link in the content page itself with the proper path to the styles

    hth,

    mcm

  • Re: Cant apply style to page

    02-12-2008, 3:08 PM
    • Loading...
    • razamit
    • Joined on 05-24-2006, 7:18 AM
    • Posts 21

    they are on the same level.

    it seems that the link to the stylesheet is not working. i have no idea why

    Amit

  • Re: Cant apply style to page

    02-14-2008, 5:17 AM
    Answer

    Hi,

    From the code,

    razamit:
    link href="GeneralStyles.css" rel="stylesheet" type="text/css" />

    we can see, the css file and the master page are in the same level,

    and from this we can see:

    razamit:
    <%@ Page Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test.WebForm1" Title="Untitled Page" %>
     

    they should be  at the root level, aren't they?

    But from this we can see:

    razamit:
    <script src="../Scripts/PostPage.js" type="text/javascript"></script>

    this content page is not at root node, so maybe this is the cause of your problem.

    To slove your problem, you can do like this:

    <link href='<%# Page.ResolveUrl("~/GeneralStyles.css") %>' rel="stylesheet" type="text/css" />

    In fact, if you refer the css file in the master page, but not all the pages work well. Bacause it is related to path of the content page.

    The master page class derives from the UserControl class. When the application is executing, the master page just like  another child control.

    In addition, you also can use the absolute path to refer the css file, but you should make sure the link works at server:

    for example:

    <link href='~/GeneralStyles.css'' rel="stylesheet" type="text/css" runat=server />

    Hope it helps.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Yours sincerely,
    Amanda Wang
    Microsoft Online Community Support
Page 1 of 1 (6 items)
Microsoft Communities
Page view counter