Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

master pages and css

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sir Psycho - 29 Aug 2007 07:55 GMT
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 :)
Alexey Smirnov - 29 Aug 2007 08:23 GMT
> Hello
>
[quoted text clipped - 11 lines]
>
> 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/microsoft.public.dotnet.framework.aspnet/browse_t
hread/thread/cd61cb0ba720710d

vMike - 29 Aug 2007 14:09 GMT
> Hello
>
[quoted text clipped - 11 lines]
>
> 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
gerry - 29 Aug 2007 14:22 GMT
http://www.pluralsight.com/blogs/ted/archive/2005/08/31/14437.aspx

> Hello
>
[quoted text clipped - 11 lines]
>
> any help would....help :)
Alan Silver - 30 Aug 2007 09:43 GMT
>http://www.pluralsight.com/blogs/ted/archive/2005/08/31/14437.aspx

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

Signature

Alan Silver
(anything added below this line is nothing to do with me)

Vince - 30 Aug 2007 14:31 GMT
On Aug 30, 6:43 pm, Alan Silver <alan-sil...@nospam.thanx.invalid>
wrote:
> In article <#6Gx1#j6HHA....@TK2MSFTNGP02.phx.gbl>, gerry
> <g...@nospam.nospam> writes
[quoted text clipped - 35 lines]
> Alan Silver
> (anything added below this line is nothing to do with me)

Thats a nice and clean approach. Thank you Alan!
vMike - 30 Aug 2007 16:16 GMT
>>http://www.pluralsight.com/blogs/ted/archive/2005/08/31/14437.aspx
>
[quoted text clipped - 28 lines]
>
> 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
Alan Silver - 30 Aug 2007 16:56 GMT
>> This is *much* easier than using the ASP.NET objects to modify the <head>
>> programmatically.
>
>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

Signature

Alan Silver
(anything added below this line is nothing to do with me)

vMike - 30 Aug 2007 18:10 GMT
>>> This is *much* easier than using the ASP.NET objects to modify the
>>> <head>
[quoted text clipped - 13 lines]
>
> 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
Alan Silver - 30 Aug 2007 18:47 GMT
<snip>
>> 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.

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

Signature

Alan Silver
(anything added below this line is nothing to do with me)

Alexey Smirnov - 31 Aug 2007 09:34 GMT
On Aug 30, 7:47 pm, Alan Silver <alan-sil...@nospam.thanx.invalid>
wrote:
> In article <nSCBi.24444$7e6.10...@bignews4.bellsouth.net>, vMike
> <Michael.Geo...@5nerrawgenospam.com> writes
[quoted text clipped - 15 lines]
> Alan Silver
> (anything added below this line is nothing to do with me)

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.
Alan Silver - 31 Aug 2007 11:31 GMT
>On Aug 30, 7:47 pm, Alan Silver <alan-sil...@nospam.thanx.invalid>
>wrote:
[quoted text clipped - 18 lines]
>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

Signature

Alan Silver
(anything added below this line is nothing to do with me)


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.