Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jan 2013
    Location
    Oregon
    Posts
    34
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Exclamation Nesting pages in folders.

    In my aspx.net site my master page contains the links to all stylesheets. Whenever I try to put one of my pages that use that master page in a subfolder they look right html wise but none of the styling is passed over and all pictures in the master page don't appear either. I know this is a problem with how I'm linking to the stylesheet and the images but I don't know how to fix it. It's assuming that everything should be in the same folder as the page but that isn't the case...Has anyone else experienced this?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,169
    Thanks
    80
    Thanked 4,560 Times in 4,524 Posts
    Why are you surprised?

    If you have folders set up as
    Code:
        /root
            main.aspx
            /css
                master.css
            /script
                code.js
            /subdir
                another.aspx
    Then even by the rules of Windows paths, the way to get to /css from "main.aspx" is via "./css/master.css" where as from "another.aspx" it would be "../css/master.css"

    So you either need to specify the correct *relative* path from your "another.aspx" file or you must specify an *absolute* path that is relative to the root of your site.

    If your /root directory (or whatever it is named, but corresponding to the above picture) is also your web root directory, then you can always get to "master.css" from *ANY* page by using "/css/master.css". That leading "/" means "start at the root directory".

    There are other solutions, especially if you control setting up virtual directories on the server, but that's the meat of it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Jan 2013
    Location
    Oregon
    Posts
    34
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I changed all the paths to have ../ in front of them in my master page. So then it worked for the sub pages but stopped working for the pages located under the root. Not sure why. So then I just created a different master page for any pages in a subfolder and it is working just how I want it. I just don't know if that is the best way to do it?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,169
    Thanks
    80
    Thanked 4,560 Times in 4,524 Posts
    I'd have to see your folder structure to know.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,901
    Thanks
    46
    Thanked 202 Times in 201 Posts
    this link kinda describes the idea... what you are dealing with is absolute vs relative paths (in your case you are doing relative)... I always find this to be a pain in the ***, and I have never cared to 'learn it'... I know the concept behind it, but what I do is (if) I am starting a new project, I get the skeleton working first with my master page and all the children, and then go to work on the rest of the site. Once you understand the theory behind it you can either learn it, or fiddle with it from time to time as I do.

    basically it boils doen to this...
    absolute paths (which you are not using) would be something like this
    Code:
    "C:\\inetpub\\wwwroot\\website1\\CSS\\MyStyles.css"  or
    @"C:\users\me\VS20##\Projects\MyProject\website1\MyStyles.css"
    As you can see they are hard coded paths. These are generally less favorable as they require the server to be exactly as coded (hard coded values can cause a lot of problems)

    then there are relative paths which looks like
    Code:
    "./CSS/MyStyles.css" or
    "../Images/MyImage.png"
    See the difference? They rely on the projects structure not the box they are sitting on, so they will always be right (also relative has forward slashes */* as opposed to absolute's backslashes *\*). Old Pedant may be able to clarify the technicalities of the dot's and slashes (again I never care to 'learn' them, I just spend the few minutes tinkering with them- but I also don't do a lot of front end work either :P)

    hope that helps some

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • Users who have thanked alykins for this post:

    samuelito.mcf (02-05-2013)

  • #6
    New Coder
    Join Date
    Jan 2013
    Location
    Oregon
    Posts
    34
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Ok I see now. I'm still not sure why when I add the ../ it only works for some and not others. But I did solve the problem by using separate master pages

  • #7
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,901
    Thanks
    46
    Thanked 202 Times in 201 Posts
    Quote Originally Posted by samuelito.mcf View Post
    Ok I see now. I'm still not sure why when I add the ../ it only works for some and not others. But I did solve the problem by using
    Code:
    separate master pages
    I would not do that. That is the opposite of coding theory (make consolidated reusable code). Creating and entirely new master page to accomodate a relative path is.... bad. Play around with the dot's and slahses until you get it right. That's why I said do it first, before you have invested a lot into the project and start-ups for the app are quick. You also need to make sure you are clearing your cache. The simplest way I have found to do this is to put a simple .png in the folders I want to map- then it will either load the image or it won't... then once everything is kosher, remove the image and links to it (but copy the path structure!!!)

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #8
    New Coder
    Join Date
    Jan 2013
    Location
    Oregon
    Posts
    34
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by alykins View Post
    I would not do that. That is the opposite of coding theory (make consolidated reusable code). Creating and entirely new master page to accomodate a relative path is.... bad. Play around with the dot's and slahses until you get it right. That's why I said do it first, before you have invested a lot into the project and start-ups for the app are quick. You also need to make sure you are clearing your cache. The simplest way I have found to do this is to put a simple .png in the folders I want to map- then it will either load the image or it won't... then once everything is kosher, remove the image and links to it (but copy the path structure!!!)
    Yes, that's what I figured. I'll continue to fool around with it. Thanks for the suggestions!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •