CSS in MasterPages

R

Rbrt

I have a master page I want to use a CSS stylesheet for. I put the link tag
in the master page markup, like this <link href="Styles/MyStyle.css"
rel="stylesheet" type="text/css" />

It works fine in Visual Studio design view when I look at a content page
that uses the master page. However, when I run my web site app, the
stylesheet markup mysteriously disappears. Does anybody have any ideas? This
is kind of baffling.
 
S

Scott Roberts

Is the content page in a different folder than the master page? Try an
absolute path in your css link. Or better yet, use Themes.
 
R

Rbrt

What is frustrating is that if I use themes and look at the source of the
page I can see that the Styleheet is being inked in as it is supposed to be.
It just isn't doing anything.
 
S

SMiGL

I have a master page I want to use a CSS stylesheet for. I put the link tag
in the master page markup, like this <link href="Styles/MyStyle.css"
rel="stylesheet" type="text/css" />

It works fine in Visual Studio design view when I look at a content page
that uses the master page. However, when I run my web site app, the
stylesheet markup mysteriously disappears. Does anybody have any ideas? This
is kind of baffling.

Improve you markup.
<link rel="Stylesheet" href="~/Styles/MyStyle.css" runat="server" />
 
R

Rbrt

I have tried every variation of the link markup I can think of. As I said,
the css works in design view. It is just at runtime that it disappears.
 
R

Rbrt

I have forms authentication but the web.config file has a location entry for
the css file that should make it accessible. I've played around with it quite
a bit but no luck.
 
R

Rbrt

Well it appears that I can get skins to work but CSS simply will not work no
matter what I do. I am giving up on CSS and instead of defining things like
tables in html, I am using asp, which is a ridiculous increase in server load
but what else can I do? I want to use CSS to save time, but have already
wasted an entire bloody day on this and have to get on with the job.

Very, very frustrating. It is hard to imagine something more basic to web
development than CSS and to have this sort of problem is just not acceptable.
 
D

David Wier

What exactly do you mean, regarding themes, that they 'don't work'

When the Master page includes the exact correct theme, I have had no
problems using themes with CSS files.
Of course, I assign my theme in the Web.config file

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
 
S

Scott Roberts

To verify that your location entry is working, try typing the url to the CSS
file directly into your browser address bar. Do you get an error?
 
R

Rbrt

No. It directs me to the logon page. Once I have logged in, I can type the
url of the css into the browser address bar and it asks me if I want to save
it to my hard drive. As I said, it displays the css markup in design view,
but not at runtime.

On the other hand, skins do not show up at design time but do show up at run
time.

Pretty weird.
 
H

Hans Nieuwenhuis

Hi,

I have noticed many times that changes in my stylesheets are not immediately
effectuated at runtime...

Internet Explorer has cached a previous version of my stylesheet file then.

I have to manually delete cached files in Internet Explorer: Tools |
Internet Options, tabpage 'general', press 'delete...' in 'Browsing history'
and then press 'delete files...'

After that I press F5 and then my changes are effective.

Hope this helps,

Hans
 
R

Rbrt

Skins do work, but CSS does not. I am declaring the theme in the Content page
and have EnableTheming=true in both Master and Content pages. I did try
declaring it in the web.comfig and it made no difference.

CSS will work at design time only if I put a <link rel....> declaration in
the Master Page. At run time, the markup disappears.
 
R

Rbrt

Thank you very much for your suggestion. I tried it but it didn't help.

I will keep checking here to see if there are any other suggestions, and I
am grateful for the advice you have all given, but I have to move on with the
project. I am not going to waste any more time on CSS but will put the markup
in the Master pages directly. At least that will provide some level of
reusability and control.

Robert
 
S

Scott Roberts

I can understand your frustration, but rest assured that CSS *does* work.
It's just not working for you. ;)

What I usually do when I have a particularly frustrating problem is try to
create a very simple project that exhibits the problem. You can then share
that simple project with the community and they can help you troubleshoot.
More often than not, I am *unable* to duplicate my problem in a new, simple
project - which means that I've got something whacked in my big, complicated
project. Then it's a matter of finding out "what's different".

Perhaps you could try that. Create a simple web project (no security or
anything) and see if your CSS file works. Assuming it does, keep adding
things to your sample until it breaks. Then share that project with us.

Scott
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top