all groups > asp.net > august 2007 >
asp.net :
master pages and css
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 :)
[quoted text, click to view] On Aug 29, 8:55 am, Sir Psycho <panuccio.vi...@gmail.com> wrote: > 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/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/cd61cb0ba720710d
[quoted text, click to view] "Sir Psycho" <panuccio.vince@gmail.com> wrote in message news:1188370509.123074.17020@l22g2000prc.googlegroups.com... > 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
http://www.pluralsight.com/blogs/ted/archive/2005/08/31/14437.aspx [quoted text, click to view] "Sir Psycho" <panuccio.vince@gmail.com> wrote in message news:1188370509.123074.17020@l22g2000prc.googlegroups.com... > 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 :) >
In article <#6Gx1#j6HHA.464@TK2MSFTNGP02.phx.gbl>, gerry <germ@nospam.nospam> writes [quoted text, click to view] 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 -- Alan Silver
On Aug 30, 6:43 pm, Alan Silver <alan-sil...@nospam.thanx.invalid> [quoted text, click to view] wrote: > In article <#6Gx1#j6HHA....@TK2MSFTNGP02.phx.gbl>, gerry > <g...@nospam.nospam> writes > > > 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 > > -- > Alan Silver > (anything added below this line is nothing to do with me) Thats a nice and clean approach. Thank you Alan!
[quoted text, click to view] "Alan Silver" <alan-silver@nospam.thanx.invalid> wrote in message news:CUStGi1eMo1GFwLW@nospamthankyou.spam... > In article <#6Gx1#j6HHA.464@TK2MSFTNGP02.phx.gbl>, gerry > <germ@nospam.nospam> writes >> 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 > > -- > Alan Silver > (anything added below this line is nothing to do with me) 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
[quoted text, click to view] "Alan Silver" <alan-silver@nospam.thanx.invalid> wrote in message news:hPiVAWBfiu1GFwvJ@nospamthankyou.spam... > In article <_aBBi.3995$Y7.2146@bignews3.bellsouth.net>, vMike > <Michael.George@5nerrawgenospam.com> writes >>> 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 > > -- > Alan Silver > (anything added below this line is nothing to do with me
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
In article <_aBBi.3995$Y7.2146@bignews3.bellsouth.net>, vMike <Michael.George@5nerrawgenospam.com> writes [quoted text, click to view] >> 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 -- Alan Silver
In article <nSCBi.24444$7e6.10911@bignews4.bellsouth.net>, vMike <Michael.George@5nerrawgenospam.com> writes <snip> [quoted text, click to view] >> 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 -- Alan Silver
On Aug 30, 7:47 pm, Alan Silver <alan-sil...@nospam.thanx.invalid> [quoted text, click to view] wrote: > In article <nSCBi.24444$7e6.10...@bignews4.bellsouth.net>, vMike > <Michael.Geo...@5nerrawgenospam.com> writes > <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 > > -- > 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.
In article <1188549260.979291.109750@i13g2000prf.googlegroups.com>, Alexey Smirnov <alexey.smirnov@gmail.com> writes [quoted text, click to view] >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 >> <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. >> > >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 -- Alan Silver
Don't see what you're looking for? Try a search.
|
|
|