473,513 Members | 4,753 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Applying stylesheet styles to master page

Hi,

I've a a site with nested master pages and content pages. I tried using
a theme with a stylesheet in the app_themes directory referencing it in
the web.config file from a pages tag theme attribute. This works for
the content pages, but it doesn't seem able to apply the styles to the
top master page even though I did set the master head tag to runat
server. Is this by design? If so, what is the best way to apply styles
to the top master page content? What did work for me was to add a style
sheet link in the master page header but this doesn't seem to be a very
elegant solution to me; my goal is to have site wide styles applied to
all masters and content pages from a single stylesheet. Is applying
styles to the header programatically from the content pages code behind
a better answer? If so, an example would be much appreciated!

Thanks for any help on this!

Nov 20 '05 #1
7 3480
Hi,

to dynamically add a stylesheet from a MasterPage, use the following
code inside the OnLoad for instance:

HtmlLink link = new HtmlLink();
link.Href = "MyStylesheet.css"
link.Attributes.Add(HtmlTextWriterAttribute.Rel.To String(),"stylesheet");
Page.Header.Controls.Add(link);

Your other questions I do not know about.
Grtz, Wouter

Nov 20 '05 #2
The master and the page get merged and rendered as a single page into the
browser, so I'm not sure why using a CSS from App_Themes isn't working for
you -- try looking at the rendered HTML source and perhaps there's something
wrong with the CSS class you're using in the master?

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

I've a a site with nested master pages and content pages. I tried
using a theme with a stylesheet in the app_themes directory
referencing it in the web.config file from a pages tag theme
attribute. This works for the content pages, but it doesn't seem able
to apply the styles to the top master page even though I did set the
master head tag to runat server. Is this by design? If so, what is the
best way to apply styles to the top master page content? What did work
for me was to add a style sheet link in the master page header but
this doesn't seem to be a very elegant solution to me; my goal is to
have site wide styles applied to all masters and content pages from a
single stylesheet. Is applying styles to the header programatically
from the content pages code behind a better answer? If so, an example
would be much appreciated!

Thanks for any help on this!

Nov 21 '05 #3
Here's a cleaner (to read) implementation ...

protected void Page_Init(object sender, EventArgs e)
{
// Your comments here...
HtmlLink link = new HtmlLink();
link.Href = "~/StyleSheet.css";
link.Attributes.Add("rel", "stylesheet");
link.Attributes.Add("type", "text/css");
Page.Header.Controls.Add(link);
}

Note the use of Page_Init emits the declaration 'before' the stylesheet
declaration generated by the Theme. If you want or need a stylesheet to
over-ride styles used by the Theme put the code shown above into the
Page_Load event.

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

"Wouter van Vugt" <wo*****@infosupport.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi,

to dynamically add a stylesheet from a MasterPage, use the following
code inside the OnLoad for instance:

HtmlLink link = new HtmlLink();
link.Href = "MyStylesheet.css"
link.Attributes.Add(HtmlTextWriterAttribute.Rel.To String(),"stylesheet");
Page.Header.Controls.Add(link);

Your other questions I do not know about.
Grtz, Wouter

Nov 21 '05 #4
I got started writing all of my style declarations in the theme.css file
located in the App_Themes folders. One great big collection of declarations
in a single file. A bad habit it seems and perhaps a misunderstanding of how
other aspects of Themes actually work because using a monolithic file
provides no mechanism for browser dependent styles so I became motivated to
write a separate style sheet into the head element.

<%= Clinton Gallagher
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:b8**************************@msnews.microsoft .com...
The master and the page get merged and rendered as a single page into the
browser, so I'm not sure why using a CSS from App_Themes isn't working for
you -- try looking at the rendered HTML source and perhaps there's
something wrong with the CSS class you're using in the master?

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

I've a a site with nested master pages and content pages. I tried
using a theme with a stylesheet in the app_themes directory
referencing it in the web.config file from a pages tag theme
attribute. This works for the content pages, but it doesn't seem able
to apply the styles to the top master page even though I did set the
master head tag to runat server. Is this by design? If so, what is the
best way to apply styles to the top master page content? What did work
for me was to add a style sheet link in the master page header but
this doesn't seem to be a very elegant solution to me; my goal is to
have site wide styles applied to all masters and content pages from a
single stylesheet. Is applying styles to the header programatically
from the content pages code behind a better answer? If so, an example
would be much appreciated!

Thanks for any help on this!


Nov 21 '05 #5
Unfortunately, that throws an error for me at :

Page.Header.Controls.Add(link);
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Here's a cleaner (to read) implementation ...

protected void Page_Init(object sender, EventArgs e)
{
// Your comments here...
HtmlLink link = new HtmlLink();
link.Href = "~/StyleSheet.css";
link.Attributes.Add("rel", "stylesheet");
link.Attributes.Add("type", "text/css");
Page.Header.Controls.Add(link);
}

Note the use of Page_Init emits the declaration 'before' the stylesheet declaration
generated by the Theme. If you want or need a stylesheet to over-ride styles used by the
Theme put the code shown above into the Page_Load event.

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

"Wouter van Vugt" <wo*****@infosupport.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi,

to dynamically add a stylesheet from a MasterPage, use the following
code inside the OnLoad for instance:

HtmlLink link = new HtmlLink();
link.Href = "MyStylesheet.css"
link.Attributes.Add(HtmlTextWriterAttribute.Rel.To String(),"stylesheet");
Page.Header.Controls.Add(link);

Your other questions I do not know about.
Grtz, Wouter


Nov 21 '05 #6
On Mon, 21 Nov 2005 13:52:05 -0400, "Juan T. Llibre"
<no***********@nowhere.com> wrote:
Unfortunately, that throws an error for me at :

Page.Header.Controls.Add(link);


I have a guess at what is happening:

You'll need a <head> element with runat="server", otherwise you'll see
a NullReferenceException.

--
Scott
http://www.OdeToCode.com/blogs/scott/
Nov 21 '05 #7
You nailed that one, Scott.
Thanks.

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:56********************************@4ax.com...
On Mon, 21 Nov 2005 13:52:05 -0400, "Juan T. Llibre"
<no***********@nowhere.com> wrote:
Unfortunately, that throws an error for me at :

Page.Header.Controls.Add(link);

I have a guess at what is happening:

You'll need a <head> element with runat="server", otherwise you'll see
a NullReferenceException.

Nov 21 '05 #8

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

Similar topics

2
2803
by: Jan Roland Eriksson | last post by:
Archive-name: www/stylesheets/authoring-faq Posting-Frequency: twice a week (Mondays and Thursdays) Last-modified: August 28, 2002 Version: 1.15 URL: http://css.nu/faq/ciwas-aFAQ.html...
3
4315
by: Jamie | last post by:
Hi, Thanks for the excellent answer to my last question! One more: Does anyone have a method they follow for organizing stylesheets themselves? They seem like they can get bloated and hard to...
0
1941
by: Jan Roland Eriksson | last post by:
Archive-name: www/stylesheets/authoring-faq Posting-Frequency: twice a week (Mondays and Thursdays) Last-modified: April 10, 2003 Version: 1.16 URL: http://css.nu/faq/ciwas-aFAQ.html Maintainer:...
0
423
by: sasquatch | last post by:
Hi, I've a a site with nested master pages and content pages. I tried using a theme with a stylesheet in the app_themes directory referencing it in the web.config file from a pages tag theme...
2
6913
by: SR | last post by:
I have started a web site using ASP.NET 2.0. I would like to centralize all of my classes in a StyleSheet but I cannot figure out how to link the StyleSheet to a Content Page since there is no...
0
1358
by: Jeff | last post by:
ASP.NET 2.0 I have problem with the markup and skin file below, this table isn't displayed. webpage <asp:Table ID="compose" SkinID="compose" runat="server"> <asp:TableRow> <asp:TableCell...
6
3580
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
I want to insert a CSS Stylesheet file in a <LINKtag inside my MasterPage so that it will work in all of the the ASPX pages that use that MasterPage (no matter where the page is in the directory...
9
4445
by: Guillaume Dargaud | last post by:
Hello all, I have a strange problem with a new install of Gallery2: Firefox does not display the style of the pages while IE does (but nobody I know uses IE). I'm not familiar with the way...
8
11766
by: Mort Strom | last post by:
Right now the header of my master page contains all of the CSS styles for all of the pages that might be loaded in my ContentPlaceHolder. The problem is that my <styletag is getting too large to...
0
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.