views:

122

answers:

3

In the head portion of my Master page i have a link to an external CSS file

<link href="style.css" rel="stylesheet" type="text/css" />

Although i am able to apply the style in child pages in design time...

<asp:Label ID="Label" runat="server" CssClass="BodyText" Text="This is a link"></asp:Label>

...in run time child pages have no style.

So, What am i missing here?

+2  A: 

If your child pages are in a subdirectory, they'll expect the style sheet in that directory as well. changing the reference to the style sheet to ../style.css or /style.css should help.

Jens Schauder
+1 Always reference style sheets from the root
Paulo Santos
+1  A: 

Try using the root operator "~" for stylesheets in your master page:

<link type="text/css" href="~/css/style.css" rel="stylesheet" />

ASP.NET resolves the ~ operator to the root of the current application. You can use the ~ operator in conjunction with folders to specify a path that is based on the current root.

Daniel Vassallo
+1  A: 

The path to the CSS file (and any other file - images, javascript, etc) is relative to the page (the page address in the browser). If the master page is in a different folder than the page, then the css file may not be found.

Try using either an absolute path, a path relative to the root, or a path to the CSS file like this:

<link href="~/style.css" rel="stylesheet" type="text/css" />
Gabriel McAdams