master pages and css

S

Sir Psycho

Hello

I understand how master pages work with containers.

How would i go about having a stylesheet for one of my containers in a
different aspx file considering that the <head> element is in the
master file? Putting it in the master file means it will be included
for all.

once using master pages, aspx files only have this

<asp:Content ID="ContentSiteBody" ContentPlaceHolderID="SiteBody"
Runat="Server">

any help would....help :)
 
G

Guest

Hello

I understand how master pages work with containers.

How would i go about having a stylesheet for one of my containers in a
different aspx file considering that the <head> element is in the
master file? Putting it in the master file means it will be included
for all.

once using master pages, aspx files only have this

<asp:Content ID="ContentSiteBody" ContentPlaceHolderID="SiteBody"
Runat="Server">

any help would....help :)

you can use following technique

Style s = new Style();
s.BackColor = System.Drawing.Color.Red;
Page.Header.StyleSheet.CreateStyleRule(s, this, "BODY");

this would change the background of your content page

http://groups.google.com/group/micr....aspnet/browse_thread/thread/cd61cb0ba720710d
 
V

vMike

Sir Psycho said:
Hello

I understand how master pages work with containers.

How would i go about having a stylesheet for one of my containers in a
different aspx file considering that the <head> element is in the
master file? Putting it in the master file means it will be included
for all.

once using master pages, aspx files only have this

<asp:Content ID="ContentSiteBody" ContentPlaceHolderID="SiteBody"
Runat="Server">

any help would....help :)
Another method would be to create a writeable property in your master page
which allows you to set the css for the page being loaded. I have done this
for metatags and titles also.

Mike
 
A

Alan Silver

gerry said:

No disrespect to anyone, but I don't see why people make such heavy work
out of adding stylesheets, meta tags, etc when using master pages.

Sure you can jump through hoops like this, but it's way easier just to
have a contentplaceholder in the <head> section of the (X)HTML in the
master page, then on content pages where you want to something, you just
use a content tag and insert the code.

For example, the top of a master page could look like this...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head runat="server">
<title>Untitled Page</title>
<asp:ContentPlaceHolder ID="cplHead" runat="server" />
</head>
<body>

.....and the content page would include this...

<asp:Content ContentPlaceHolderID="cplHead" runat="server">
<link href="fred.css" ..../>
<meta name="ferret" content="furry" />
</asp:Content>

This is *much* easier than using the ASP.NET objects to modify the
<head> programmatically.

HTH
 
V

Vince

No disrespect to anyone, but I don't see why people make such heavy work
out of adding stylesheets, meta tags, etc when using master pages.

Sure you can jump through hoops like this, but it's way easier just to
have a contentplaceholder in the <head> section of the (X)HTML in the
master page, then on content pages where you want to something, you just
use a content tag and insert the code.

For example, the top of a master page could look like this...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head runat="server">
<title>Untitled Page</title>
<asp:ContentPlaceHolder ID="cplHead" runat="server" />
</head>
<body>

....and the content page would include this...

<asp:Content ContentPlaceHolderID="cplHead" runat="server">
<link href="fred.css" ..../>
<meta name="ferret" content="furry" />
</asp:Content>

This is *much* easier than using the ASP.NET objects to modify the
<head> programmatically.

HTH

Thats a nice and clean approach. Thank you Alan!
 
V

vMike

Alan Silver said:
No disrespect to anyone, but I don't see why people make such heavy work
out of adding stylesheets, meta tags, etc when using master pages.

Sure you can jump through hoops like this, but it's way easier just to
have a contentplaceholder in the <head> section of the (X)HTML in the
master page, then on content pages where you want to something, you just
use a content tag and insert the code.

For example, the top of a master page could look like this...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head runat="server">
<title>Untitled Page</title>
<asp:ContentPlaceHolder ID="cplHead" runat="server" />
</head>
<body>

....and the content page would include this...

<asp:Content ContentPlaceHolderID="cplHead" runat="server">
<link href="fred.css" ..../>
<meta name="ferret" content="furry" />
</asp:Content>

This is *much* easier than using the ASP.NET objects to modify the <head>
programmatically.

HTH

No disrespect taken. I think it depends a lot on how much flexibly you
need. If it you are trying to build an app that is going to have a lot of
flexibility, I prefer properties.

Mike
 
A

Alan Silver

vMike said:
No disrespect taken. I think it depends a lot on how much flexibly you
need. If it you are trying to build an app that is going to have a lot
of flexibility, I prefer properties.

Out of interest, why? Having the <head> stuff inside a content tag still
allows flexibility. I showed a static way to do it, but there's nothing
wrong with putting a Literal control in the <head> content tag and
setting the stylesheet dynamically. Works the same as a property, but
much simpler IMO.

I'd be interested to hear why you prefer properties.

Ta ra
 
V

vMike

Alan Silver said:
Out of interest, why? Having the <head> stuff inside a content tag still
allows flexibility. I showed a static way to do it, but there's nothing
wrong with putting a Literal control in the <head> content tag and setting
the stylesheet dynamically. Works the same as a property, but much simpler
IMO.

I'd be interested to hear why you prefer properties.

Ta ra

I find it easier to code. I admit that setting the style sheet is not the
best example for using properties. I use it for setting menus, titles and
body attributes. Maybe it is just a preference thing.

Mike
 
A

Alan Silver

I'd be interested to hear why you prefer properties.

I find it easier to code. I admit that setting the style sheet is not the
best example for using properties. I use it for setting menus, titles and
body attributes. Maybe it is just a preference thing.[/QUOTE]

OK, for titles and body attributes it could be sensible, although I
often bung a Literal in the <title> tag and do the same thing! Horses
for courses I guess.

Ta ra
 
G

Guest

OK, for titles and body attributes it could be sensible, although I
often bung a Literal in the <title> tag and do the same thing! Horses
for courses I guess.

Ta ra

I think this is just a preference thing and a matter of the
architecture. I can say, if MasterPage has to be different for
different sets of content pages, than it is not really a "master". In
this case you can also have MasterPage2 with different CSS on it and
you can use it for that set of content pages where the style should be
different.
 
A

Alan Silver

I think this is just a preference thing and a matter of the
architecture. I can say, if MasterPage has to be different for
different sets of content pages, than it is not really a "master". In
this case you can also have MasterPage2 with different CSS on it and
you can use it for that set of content pages where the style should be
different.

Could be, although I have had cases where one particular page required
extra CSS, and I didn't want to include that in the CSS for every page,
so I just added an extra link in the header for that one page. Certainly
wasn't worth doing a new master page for just that.

Ta ra
 

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,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top