referencing to style sheet

Discussion in 'ASP .Net' started by David C, Feb 5, 2006.

  1. David C

    David C Guest

    I am not fully understanding how to refer to another file in the aspx
    page.

    There is one style sheet which I need to refer to and it is in the root
    directory

    <LINK href="styles.css" type="text/css" rel="stylesheet">

    So how to I refer to that from aspx pages in various sub-directories?
    It works if I use relative paths (../styles.css), but not if you are
    going to the aspx file from another aspx file from a different
    directory.

    Tried ~/styles.css hoping that the reference will work no matter where,
    but it does not work.

    *** Sent via Developersdex http://www.developersdex.com ***
    David C, Feb 5, 2006
    #1
    1. Advertising

  2. David C

    Alec MacLean Guest

    David,

    You can add further relative pathing;

    /folder_with_css_file
    |
    - sub-folder
    |
    -sub-sub-folder

    With aspx page in "sub-sub-folder", you would extend your realtive path
    navigation to add another parent folder directive (../), like this;

    <LINK href="../../styles.css" type="text/css" rel="stylesheet">
    ^^

    Hope that helps

    Al


    "David C" <> wrote in message
    news:eBa%...
    >
    >
    > I am not fully understanding how to refer to another file in the aspx
    > page.
    >
    > There is one style sheet which I need to refer to and it is in the root
    > directory
    >
    > <LINK href="styles.css" type="text/css" rel="stylesheet">
    >
    > So how to I refer to that from aspx pages in various sub-directories?
    > It works if I use relative paths (../styles.css), but not if you are
    > going to the aspx file from another aspx file from a different
    > directory.
    >
    > Tried ~/styles.css hoping that the reference will work no matter where,
    > but it does not work.
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    Alec MacLean, Feb 5, 2006
    #2
    1. Advertising

  3. David C

    Josh Twist Guest

    In order for ASP.NET to resolve the ~/styles.css the element must be a
    server control:

    <link href="styles.css" type="text/css" rel="stylesheet" runat="server"
    />

    I don't think this works in ASP.NET 1.x though, but this does:

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

    Josh
    http://www.thejoyofcode.com/
    Josh Twist, Feb 5, 2006
    #3
  4. David C

    David C Guest

    I DO NOT want to have to use relative paths, so this one will not work.

    "Alec MacLean" <> wrote in message
    news:...
    > David,
    >
    > You can add further relative pathing;
    >
    > /folder_with_css_file
    > |
    > - sub-folder
    > |
    > -sub-sub-folder
    >
    > With aspx page in "sub-sub-folder", you would extend your realtive path
    > navigation to add another parent folder directive (../), like this;
    >
    > <LINK href="../../styles.css" type="text/css" rel="stylesheet">
    > ^^
    >
    > Hope that helps
    >
    > Al
    >
    >
    > "David C" <> wrote in message
    > news:eBa%...
    >>
    >>
    >> I am not fully understanding how to refer to another file in the aspx
    >> page.
    >>
    >> There is one style sheet which I need to refer to and it is in the root
    >> directory
    >>
    >> <LINK href="styles.css" type="text/css" rel="stylesheet">
    >>
    >> So how to I refer to that from aspx pages in various sub-directories?
    >> It works if I use relative paths (../styles.css), but not if you are
    >> going to the aspx file from another aspx file from a different
    >> directory.
    >>
    >> Tried ~/styles.css hoping that the reference will work no matter where,
    >> but it does not work.
    >>
    >> *** Sent via Developersdex http://www.developersdex.com ***

    >
    >
    David C, Feb 5, 2006
    #4
  5. David C

    David C Guest

    It works....Thanks...BUT, got a big problem. Once I do that to a page, it
    does not let me add a literal control to the page any more, and it shows the
    following error message.

    The Controls collection cannot be modified because the control contains code
    blocks (i.e. <% ... %>).

    "Josh Twist" <> wrote in message
    news:...
    > In order for ASP.NET to resolve the ~/styles.css the element must be a
    > server control:
    >
    > <link href="styles.css" type="text/css" rel="stylesheet" runat="server"
    > />
    >
    > I don't think this works in ASP.NET 1.x though, but this does:
    >
    > <link href="<%=Page.ResolveUrl("~/styles.css")%>" type="text/css"
    > rel="stylesheet" />
    >
    > Josh
    > http://www.thejoyofcode.com/
    >
    David C, Feb 5, 2006
    #5
  6. David C

    Josh Twist Guest

    Hmm... you could put that code into a user control and place the user
    control on each page instead of the <link> element itself.

    Josh
    http://www.thejoyofcode.com/
    Josh Twist, Feb 6, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marc Nederhoff

    Adding style sheet dynamicaly

    Marc Nederhoff, Nov 5, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    413
    charles
    Nov 5, 2003
  2. Jim Heavey

    Cascading Style Sheet

    Jim Heavey, Nov 18, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    363
    Justin Musick
    Nov 19, 2003
  3. Replies:
    0
    Views:
    510
  4. Joseph Kesselman

    style sheet referencing itself?

    Joseph Kesselman, Mar 20, 2008, in forum: XML
    Replies:
    2
    Views:
    511
    Malcolm Dew-Jones
    Mar 20, 2008
  5. Ken Varn
    Replies:
    0
    Views:
    430
    Ken Varn
    Apr 26, 2004
Loading...

Share This Page