473,323 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Multiple CSS files - proper way to do this when you have a master page?

Hi all,

I have enough experience with HTML/classic ASP to get by, and I'm trying to
learn ASP.NET.

Traditionally, I've taken the habit of breaking out extra-long CSS files
into multiple, smaller ones, and referring to them in my HTML/ASP files on
an as-needed basis. Essentially, I've organized things as:

/default.asp
/somepage.asp
/common.css
/area1 (folder)
/area1/default.asp
/area1/somepage.asp
/area1/someotherpage.asp
/area1/area1.css
/area2 (folder)
/area2/default.asp
/area2/somepage.asp
/area2/someotherpage.asp
/area2/area2.css

common.css contains styles that should apply to all pages on my site.
area1.css contains styles that only apply to the files in the area1 folder,
area2.css applies to the files in the area2 folder, etc. Then the
individual files all include /common.css, and the asp files in the
subfolders additionally include the respective area[x].css (only as needed),
using multiple <link href="whatever.css" [...]tags in the <headsection.
This scheme has served me well for years.

Now...my problem with doing this "the ASP.NET way"...my master page includes
the tag for common.css. This is great as all my content pages automatically
include it. However, I need to include the other area[x].css files on a
page-by-page (content page by content page) basis. The master's already
defined and closed the <headtag.

I've found out (by accident) that you can put other <link href=...tags in
the content pages and they'll render in the browser fine, but that confuses
VS2005 (you can't switch to Design view)--a sure sign that this isn't the
way you "should" be doing things.

I'm currently looking at skins/themes, but they seem to bring along their
own set of problems that I'm not ready to sort out just yet--I'd really love
to just be able to have my content pages include their own .css files (not
to override the common.css files, but rather to complement it). Does it
make sense to try to do something in the Page_Load() event? What's the
proper way to do this?

Any guidance appreciated...
Jul 11 '07 #1
6 3475
I hate to reply to my own messages, but I've gotta follow up...

Ok...I've figured out that you can create a theme folder and put multiple
..css files in it, put a reference to the theme in the content page, and then
the styles are automatically available in that page...

Only, I haven't made any reference to any specific .css file--meaning,
apparently, that any aspx file that simply references a theme will use any
and all .css files that exist under that theme's folder. Is that correct?
Can I control that? I'd like to keep organizing things in separate .css
files, but don't necessarily want them *all* automatically included in aspx
pages that don't need them.

Surely the solution isn't to create multiple themes, one for each .css file,
and only use that theme in the page(s) that need it. Obviously I'm working
against how the system is intended to be used...

From what I've been seeing, there's an awful lot of books that introduce
various ASP.NET topics, but very few present things in a "this is how you
now do things if you're from a classic HTML/ASP background" fashion.
Finding the exact keywords on Google to find relevant results for this sort
of thing also seem to escape me...
Jul 11 '07 #2
In article <#I**************@TK2MSFTNGP03.phx.gbl>, Homer J. Simpson
<ro**@127.0.0.1writes
>Only, I haven't made any reference to any specific .css file--meaning,
apparently, that any aspx file that simply references a theme will use
any and all .css files that exist under that theme's folder. Is that
correct?
"Correct" meaning that this is the way MS designed it, then yes.

"Correct" meaning that this is sensible, then no.
Can I control that? I'd like to keep organizing things in separate
.css files, but don't necessarily want them *all* automatically
included in aspx pages that don't need them.
One of my long-time gripes with themes. I have tried to find a solution
to this and failed.
>Surely the solution isn't to create multiple themes, one for each .css
file, and only use that theme in the page(s) that need it. Obviously
I'm working against how the system is intended to be used...
It wouldn't work anyway. AFAIK, you can only apply one theme to an
application, you can't apply one theme to one folder and another to a
different folder.
>From what I've been seeing, there's an awful lot of books that
introduce various ASP.NET topics, but very few present things in a
"this is how you now do things if you're from a classic HTML/ASP
background" fashion.
There are a few, but given that the two are *so* different, you're
actually better off forgetting (almost) everything you learnt about
classic ASP and reading Asp.NET books as though it was something
entirely new.

Read these forums for a bit and see how many people struggle with the
changeover. Most of them suffer from trying to make ASP.NET work in the
classic ASP way. It's far better to make a clean break and treat it as a
new subject entirely.
>Finding the exact keywords on Google to find relevant results for this
sort of thing also seem to escape me...
Yeah, that can be a problem too. That's where these groups are so good!

HTH

--
Alan Silver
(anything added below this line is nothing to do with me)
Jul 18 '07 #3
>>Only, I haven't made any reference to any specific .css file--meaning,
>>apparently, that any aspx file that simply references a theme will use any
and all .css files that exist under that theme's folder. Is that correct?

"Correct" meaning that this is the way MS designed it, then yes.

"Correct" meaning that this is sensible, then no.
While I'm learning to appreciate some .NET things, I'm quickly finding that
there's a lot of things I wouldn't have designed the way they are. Well,
that's just MS being MS, I guess...been there, done that.
>Can I control that? I'd like to keep organizing things in separate .css
files, but don't necessarily want them *all* automatically included in
aspx pages that don't need them.

One of my long-time gripes with themes. I have tried to find a solution to
this and failed.
Hearing this sort of thing isn't particularly encouraging, especially when
this is one of the very first things ever I've tried doing in .NET beyond a
Hello, World page...I've been holding off on learning .NET for a very long
time (I've skipped 1.0 and 1.1 entirely), and now that I'm knee-deep into
it, the reality is such a huge contrast to the endless praise I've been
hearing for years...

Anyway...I don't know if this can be useful to you, coming from a noob such
as myself...I ended up implementing some suggestion I've stumbled upon in
some other forums. For now, I'm willing to forget all about themes.
Essentially, I put a reference to my "base" CSS file in my master page's
<headas one normally would:

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

....followed by an 'empty' one:

<link href="" id="idExtraStyleSheet" rel="stylesheet" type="text/css"
runat="server" />

....then for any page requiring an additional CSS file, I use the following
in its Page_Load() event:

MasterPage m = (MasterPage)Page.Master;
m.ExtraStyleSheetURL = "~/SomePath/UrlToMyAdditionalCssFile.css";

Of course it means I have a bogus "goes-nowhere" <link href=""tag if I
have a page that *doesn't* need an additional CSS, but that's not causing
any problem.

I'll try to figure out the equivalent "MS-way" later. I'm not holding my
breath though since there doesn't appear to be a short answer to this one.
>>From what I've been seeing, there's an awful lot of books that introduce
various ASP.NET topics, but very few present things in a "this is how you
now do things if you're from a classic HTML/ASP background" fashion.

There are a few, but given that the two are *so* different, you're
actually better off forgetting (almost) everything you learnt about
classic ASP and reading Asp.NET books as though it was something entirely
new.
While I don't necessarily disagree, the intent behind that observation was
just to suggest that I'm convinced there's a market for it. How many
long-time classic ASP coders have moved on to ASP.NET and would buy a book
to assist with the transition, as opposed to the endless supply of help-file
type of books?
Read these forums for a bit and see how many people struggle with the
changeover. Most of them suffer from trying to make ASP.NET work in the
classic ASP way. It's far better to make a clean break and treat it as a
new subject entirely.
It's really a matter of using the right tool for the right job... On one
hand, if something is doable in ASP.NET but is completely awkward, then
that's an indication that I (as a .NET newbie) don't fully understand the
how and the why. On the other, I'd rather stick with the tried-and-true
methods where it makes sense, and not do absolutely everything "the .NET
way" just because this is what MS suggests.

For one--and it's still early in my learning process--I find that ASP.NET
generates *way* more inline styles (as tag attributes) than I would ever
hand-code, especially when "the old method" can be rewritten in a much
cleaner CSS file in a line or two. I find having some server control
attributes in an aspx file, along with separate CSS files, really confuses
matters. And then, of course, not all attributes you can put in a CSS file
can be specified as server control attributes either, so I really have no
choice but to have some styles specified in one location, and others
specified elsewhere...I feel I'm stepping backwards.
>>Finding the exact keywords on Google to find relevant results for this
sort of thing also seem to escape me...

Yeah, that can be a problem too. That's where these groups are so good!
Yeah, but my gripe is that it's often quicker to find a relevant answer and
get right back to work than posting a new message and waiting for a
response. No offense to anyone here--I'm a long-time Usenet user...it's
just the nature of things...
Jul 19 '07 #4
In article <uW**************@TK2MSFTNGP02.phx.gbl>, Homer J. Simpson
<ro**@127.0.0.1writes
<snip>
>>Can I control that? I'd like to keep organizing things in separate .css
files, but don't necessarily want them *all* automatically included in
aspx pages that don't need them.

One of my long-time gripes with themes. I have tried to find a solution to
this and failed.

Hearing this sort of thing isn't particularly encouraging, especially when
this is one of the very first things ever I've tried doing in .NET beyond a
Hello, World page...I've been holding off on learning .NET for a very long
time (I've skipped 1.0 and 1.1 entirely), and now that I'm knee-deep into
it, the reality is such a huge contrast to the endless praise I've been
hearing for years...
Maybe I should qualify the comment by saying that having done ASP.NET
for a couple of years now, it is *way* better than classic ASP. Once you
get into the swing of it, you wonder how you ever did classic at all. I
look back at old sites and cringe at how badly they were implemented.
That's partly my fault and partly MS's. ASP.NET does encourage you to
make a complete separation between code and output (ie the (X)HTML), and
that's a very powerful and positive step forwards.

I could list grips I had with classic ASP was well. You just happen to
have hit one I have with ASP.NET. Themes are still a great idea, they
just need some improvement. Even as they are, they are a load better
than doing the same idea yourself.
>Anyway...I don't know if this can be useful to you, coming from a noob such
as myself...I ended up implementing some suggestion I've stumbled upon in
some other forums. For now, I'm willing to forget all about themes.
Essentially, I put a reference to my "base" CSS file in my master page's
<headas one normally would:
<snip>

Thanks for the idea. It's worth considering. You would need some central
mechanism for controlling which page got which CSS file though,
otherwise you would end up with a real mess.
>>>From what I've been seeing, there's an awful lot of books that introduce
various ASP.NET topics, but very few present things in a "this is how you
now do things if you're from a classic HTML/ASP background" fashion.

There are a few, but given that the two are *so* different, you're
actually better off forgetting (almost) everything you learnt about
classic ASP and reading Asp.NET books as though it was something entirely
new.

While I don't necessarily disagree, the intent behind that observation was
just to suggest that I'm convinced there's a market for it. How many
long-time classic ASP coders have moved on to ASP.NET and would buy a book
to assist with the transition, as opposed to the endless supply of help-file
type of books?
Dunno. I tried adapting my classic ASP way of thinking, then realised
that it was confusing rather than helping. I bought ASP.NET Unleashed by
Steven Walther and treated myself as a beginner. It was one of the best
books of it's type I ever read and got me going fast. I still use it
sometimes.
>Read these forums for a bit and see how many people struggle with the
changeover. Most of them suffer from trying to make ASP.NET work in the
classic ASP way. It's far better to make a clean break and treat it as a
new subject entirely.

It's really a matter of using the right tool for the right job... On one
hand, if something is doable in ASP.NET but is completely awkward, then
that's an indication that I (as a .NET newbie) don't fully understand the
how and the why. On the other, I'd rather stick with the tried-and-true
methods where it makes sense, and not do absolutely everything "the .NET
way" just because this is what MS suggests.
Trouble is, the "tried and true" method for classic ASP is often
completely the wrong method for ASP.NET and vice-versa. That's why I
suggested approaching ASP.NET as a newbie, it avoids the problem of
thinking you know the best way to do something, when really the way you
have in mind might be completely inappropriate for ASP.NET. It really is
a new (but highly (superior) way of thinking.
>For one--and it's still early in my learning process--I find that ASP.NET
generates *way* more inline styles (as tag attributes) than I would ever
hand-code, especially when "the old method" can be rewritten in a much
cleaner CSS file in a line or two. I find having some server control
attributes in an aspx file, along with separate CSS files, really confuses
matters. And then, of course, not all attributes you can put in a CSS file
can be specified as server control attributes either, so I really have no
choice but to have some styles specified in one location, and others
specified elsewhere...I feel I'm stepping backwards.
Hmm, sounds more like a structure issue than a problem with the way
ASP.NET handles it. I'd need to see a more concrete example before I
could say though.

I do agree about some of the markup produced by the framework. I quickly
learned never to use the Label control as it creates extra markup you
just don't need. My code tends to have things like...

<h2><asp:Label ID="fred" runat="server" /></h2>

....so I can just set the value of the literal, and know that the markup
will be clean.

I do all of my presentation with CSS, so the .aspx file tends to be very
vanilla (X)HTML and nothing more. That keeps the separation between
content and presentation very well, making better structured pages and a
much easier implementation of themes.
>>>Finding the exact keywords on Google to find relevant results for this
sort of thing also seem to escape me...

Yeah, that can be a problem too. That's where these groups are so good!

Yeah, but my gripe is that it's often quicker to find a relevant answer and
get right back to work than posting a new message and waiting for a
response. No offense to anyone here--I'm a long-time Usenet user...it's
just the nature of things...
Yup, you need to do both.

Ta ra

--
Alan Silver
(anything added below this line is nothing to do with me)
Jul 20 '07 #5
Oh, don't get me wrong--it took me no time at all to realize there's no
going back to classic ASP. Everything's such a kludge, I don't miss it at
all.
Thanks for the idea. It's worth considering. You would need some central
mechanism for controlling which page got which CSS file though, otherwise
you would end up with a real mess.
As far as my current needs go, this is more than 'good enough'. A lot of my
CSS files are mapped to a single .aspx (eg, to override styles inherited
elsewhere for that page only, or to style a control that is unique to that
page), so I don't think this is gonna be much of an issue. Of course, I was
never involved with sites with more than a dozen pages. Learning any of
this is more of a side-line for me.
Dunno. I tried adapting my classic ASP way of thinking, then realised that
it was confusing rather than helping. I bought ASP.NET Unleashed by Steven
Walther and treated myself as a beginner. It was one of the best books of
it's type I ever read and got me going fast. I still use it sometimes.
I did approach this as a beginning myself, but I still can't help thinking
"I know how to do X, now how should it be done in ASP.NET"...this is what
I'd like to see in some book or tutorial.
Trouble is, the "tried and true" method for classic ASP is often
completely the wrong method for ASP.NET and vice-versa.
"Tried and true" might have been a poor choice of words on my part--there's
an awful lot of ugly hacks that we all came up with out of necessity, and
they should be dropped at the first chance...
That's why I suggested approaching ASP.NET as a newbie, it avoids the
problem of thinking you know the best way to do something, when really the
way you have in mind might be completely inappropriate for ASP.NET. It
really is a new (but highly (superior) way of thinking.
I don't disagree. But let me ask you this: Do you get the sense that MS is
trying to get ASP.NET developers to drop style sheets and go 100%
themes/skins instead? And if so, is sticking to style sheets "working
against the framework"? I'm starting to think I just need more examples.
Most books barely scratch the surface of this topic, or are little more than
references.
>>For one--and it's still early in my learning process--I find that ASP.NET
generates *way* more inline styles (as tag attributes) than I would ever
hand-code, especially when "the old method" can be rewritten in a much
cleaner CSS file in a line or two. I find having some server control
attributes in an aspx file, along with separate CSS files, really confuses
matters. And then, of course, not all attributes you can put in a CSS
file
can be specified as server control attributes either, so I really have no
choice but to have some styles specified in one location, and others
specified elsewhere...I feel I'm stepping backwards.

Hmm, sounds more like a structure issue than a problem with the way
ASP.NET handles it. I'd need to see a more concrete example before I could
say though.
Meh. It's not such a big issue, all things considered-- I'd rather
concentrate on learning the more important features for now and get back to
this later.
I do all of my presentation with CSS, so the .aspx file tends to be very
vanilla (X)HTML and nothing more. That keeps the separation between
content and presentation very well, making better structured pages and a
much easier implementation of themes.
Great--that's what I'd try to do also. I guess it sorta answers my question
above as well...
Jul 20 '07 #6
In article <Oz**************@TK2MSFTNGP05.phx.gbl>, Homer J. Simpson
<ro**@127.0.0.1writes
>That's why I suggested approaching ASP.NET as a newbie, it avoids the
problem of thinking you know the best way to do something, when really the
way you have in mind might be completely inappropriate for ASP.NET. It
really is a new (but highly (superior) way of thinking.

I don't disagree. But let me ask you this: Do you get the sense that
MS is trying to get ASP.NET developers to drop style sheets and go 100%
themes/skins instead? And if so, is sticking to style sheets "working
against the framework"?
No, I don't get that impression. I have only used skins once. They are
OK, but I prefer to handle it all in style sheets. AFAICS, MS are quite
happy for people to use stylesheets only, I don't think they are pushing
us into skins.
I'm starting to think I just need more examples. Most books barely
scratch the surface of this topic, or are little more than references.
That's certainly true. I guess with al the other stuff in ASP.NET, this
gets pushed to the side a little.

One of the problems is that most ASP.NET developers are programmers, not
designers. CSS, themes and skins are really aimed at designers, so they
don't get as much attention as the coding.

Ta ra

--
Alan Silver
(anything added below this line is nothing to do with me)
Jul 22 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steve George | last post by:
Hi, I have a scenario where I have a master schema that defines a number of complex and simple types. I then have a number of other schemas (with different namespaces) where I would like to reuse...
0
by: Robert Sprague | last post by:
We have a corporate intranet with many web based applications. Our goal is to have a single login for the user, but we wish to pass these login credentials to each of our appications. Since...
20
by: Alan Silver | last post by:
Hello, In classic ASP, I used to use two include files on each page, one before and one after the main content, to provide a consistent layout across a web site. That way I could just change the...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
4
by: EagleRed | last post by:
I am writing an ASP.NET 2.0 application that uses more than one master page. Currently, there are two pages, Freedom1.master and Freedom2.master. I have no problems with Freedom1.master. However,...
2
by: Alec MacLean | last post by:
Hi I've just recently upgraded to VS2005 and started using/learning about the Master Pages. I'd like to know if it is possible to have separate web app projects use the master page(s) from...
3
by: MikeB | last post by:
Hello, I have a content page that is from a Master page which has 2 content panes. How do I add my forms to the content page? Each pane needs a form but you can not have multiple form tags nor...
0
by: dixonjm | last post by:
Hi, I have a master page & various pages that will use this master page. Each content page will have a CSS & JS file which will be named the same as the content page. When I try to load the CSS...
4
by: gentsquash | last post by:
On some of my course pages, I quote (with attribution) small sections of Wikipedia and the like. E.g, the top of http://en.wiktionary.org/wiki/entropy has "entropia" in Greek font, ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.