Click here to Skip to main content
11,630,144 members (78,322 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET WebForms , +
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
<link rel="Stylesheet" href="../Style/ClientStyle.css"/>

in my NestedMasterpage,
<%@ 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,
<%@ 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.
<link rel="Stylesheet" href="../../MasterPages/%3C%25=ResolveUrl(%22~/Style/ClientStyle.css%22)%20%25%3E" type="text/css" />
Posted 4-Oct-12 8:11am
Edited 4-Oct-12 20:45pm
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
<link type="text/css" href="/YourContentFolder/YourCss.css" rel="stylesheet" />
NOT
<link type="text/css" href="YourContentFolder/YourCss.css" rel="stylesheet" />
or
<link type="text/css" href="../YourContentFolder/YourCss.css" rel="stylesheet" />
  Permalink  
Comments
Minghang at 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.
Marcus Kramer at 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 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.

<head runat="server">
    <title></title>
  Permalink  
Comments
Minghang at 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)

  Print Answers RSS


Advertise | Privacy | Mobile
Web04 | 2.8.150723.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100