Click here to Skip to main content
15,885,944 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
Hello all, i just want to understand why this is happening. Consider this,
I have a masterpage(ClientMaster), a nested masterpage(Homepagenested) that references the ClientMaster.
Now, i have a folder named Webforms in the root folder. Inside this folder there are many subfolders...
say Homepage folder(Inside the Webforms folder) where there is a homepage.aspx page that references the Homepagenested Nested masterpage.In this case, when running the homepage.aspx page the
Nested masterpages and the Clientmasterpages styles goes haywire, i mean all the sidemenubars the right contents etc...are all out of place.
The shocking thing to me is that, when i create an aspx page directly under Webforms folder and not in the subfolders, the styles are maintained as if nothing happened.

I like to Keep things organized that's why i create subfolders for grouping the webforms....but it's just not working out for me.

Please, any kind of help would be appreciated. I didn't think of placing any codes here since my problem is just related to paths...i guess, but if you need the codes to
understand my problem better...then i'll be happy to place them here


EDITED

This is the way i've linked my stylesheet in ClientMaster.Master page
C#
<link rel="Stylesheet" href="../Style/ClientStyle.css"/>


in my NestedMasterpage,
C#
<%@ Master Language="C#" MasterPageFile="~/MasterPages/ClientMaster.master" AutoEventWireup="false" CodeFile="PlanYourTravelNested.master.cs" Inherits="MasterPages_PlanYourTravelNested" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link rel="Stylesheet" href="../Style/NestedStyle.css" />
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</asp:Content>

the .aspx page in the subfolder that references the NestedMaster page,
C#
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPages/PlanYourTravelNested.master" CodeFile="PlanYourTravel.aspx.cs" Inherits="WebForms_Plan_Your_Travel_PlanYourTravel" Title="Plan Your Travel" %>


this is how the link tag looks in my content pages. As you can see in the HTML file the Masterpages folder(which is in the root folder)...it is going up two directories....
FYI....i used ResolveUrl("~/Style/ClientStyle.css") to link the style sheet in the master page.
HTML
<link rel="Stylesheet" href="../../MasterPages/%3C%25=ResolveUrl(%22~/Style/ClientStyle.css%22)%20%25%3E" type="text/css" />
Posted
Updated 4-Oct-12 20:45pm
v3

If you want to use a bunch of nested folders with the same master, ensure that your css and js includes that exist on the master page are using full paths to the source instead of relative paths.
XML
<link type="text/css" href="/YourContentFolder/YourCss.css" rel="stylesheet" />

NOT
XML
<link type="text/css" href="YourContentFolder/YourCss.css" rel="stylesheet" />

or
XML
<link type="text/css" href="../YourContentFolder/YourCss.css" rel="stylesheet" />
 
Share this answer
 
Comments
Minghang 4-Oct-12 16:18pm    
hello marcus, thankyou for your quick reply...i tried your method of linking the stylesheet as you suggested but that completely breaks the link to the css file that is in my Style folder inside the root folder.
fjdiewornncalwe 4-Oct-12 17:23pm    
That would indicate that you have an incorrect absolute path. The path you put in the href needs to be complete from the root of your web application.
Minghang 5-Oct-12 1:31am    
hmmm....well my master page and the nested master pages are in a Folder called Master pages...and this folder is directly under the root of the website. So, in such a case the above reference href="/Styles/ClientStyle.css" would fail right?...so if i want to reference a css file that is in the Styles folder under the root in my masterpage...how would i go on about it??...right now everything is relative paths and fixed by visual studio itself...so i didn't bother much about it
solution provided by @Marcus is correct but i want to add one more point here
->you are facing this problem because your CSS not linked in Site.Master page correctly.

C#
<head runat="server">
    <title></title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <asp:contentplaceholder id="HeadContent" runat="server" xmlns:asp="#unknown">
    </asp:contentplaceholder>
</head>
 
Share this answer
 
Comments
Minghang 4-Oct-12 16:20pm    
hello, mandi kant...thankyou for your reply. i tried using the tilda in my link but that didn't work as well...i'm just starting to understand paths in asp.net...i didn't give much priority to this subject as i thought it would be managed automatically.
and btw...the xmlns:asp...attrib in the contentplaceholder thorws an error for me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900