By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,573 Members | 3,008 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,573 IT Pros & Developers. It's quick & easy.

I need my CSS in the master page to get reflected in content page

P: n/a
Hi,

I have one master page which has some table inside one of the <td> i
have my contentplaceholder.

on the <head> tag of the master page i have specified link to a global
CSS (stylesheet.css) file.

On my content page i have a textbox inside the contentplaceholder.

What i want is my all content page to use the same CSS file
(stylesheet.css).

If i specify on the page load

//HtmlLink cssLink = new HtmlLink();
//cssLink.Href = "StyleSheet.css";
//cssLink.Attributes.Add("rel","stylesheet");
//cssLink.Attributes.Add("type", "text/css");
//Header.Controls.Add(cssLink);

It works fine.

But this i will have to include in all my content pages, so if in case
if i want any other stylesheet file to be global, i will have to modify
code in all my content pages.

Can anybody suggest how can i specify a css file in master and inherit
that in all my content pages.

Thnx
Pushpadant

Jun 29 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
why don't you just declare the style sheet in the head section of the
master page?

....
<head>
<LINK href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
....

pu********@gmail.com wrote:
Hi,

I have one master page which has some table inside one of the <td> i
have my contentplaceholder.

on the <head> tag of the master page i have specified link to a global
CSS (stylesheet.css) file.

On my content page i have a textbox inside the contentplaceholder.

What i want is my all content page to use the same CSS file
(stylesheet.css).

If i specify on the page load

//HtmlLink cssLink = new HtmlLink();
//cssLink.Href = "StyleSheet.css";
//cssLink.Attributes.Add("rel","stylesheet");
//cssLink.Attributes.Add("type", "text/css");
//Header.Controls.Add(cssLink);

It works fine.

But this i will have to include in all my content pages, so if in case
if i want any other stylesheet file to be global, i will have to modify
code in all my content pages.

Can anybody suggest how can i specify a css file in master and inherit
that in all my content pages.

Thnx
Pushpadant


Jun 29 '06 #2

P: n/a
Neil wrote the way to do what you want but if your pages will be in
subfolders in your app you need to get the relative path of the css file:

<LINK href="<%=ResoveUrl("~stylesheet.css%>" rel="stylesheet"
type="text/css">

You can add page_load event in your master page too and make the link on
the fly.

ne**********@gmail.com wrote:
why don't you just declare the style sheet in the head section of the
master page?

...
<head>
<LINK href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
...

pu********@gmail.com wrote:
Hi,

I have one master page which has some table inside one of the <td> i
have my contentplaceholder.

on the <head> tag of the master page i have specified link to a global
CSS (stylesheet.css) file.

On my content page i have a textbox inside the contentplaceholder.

What i want is my all content page to use the same CSS file
(stylesheet.css).

If i specify on the page load

//HtmlLink cssLink = new HtmlLink();
//cssLink.Href = "StyleSheet.css";
//cssLink.Attributes.Add("rel","stylesheet");
//cssLink.Attributes.Add("type", "text/css");
//Header.Controls.Add(cssLink);

It works fine.

But this i will have to include in all my content pages, so if in case
if i want any other stylesheet file to be global, i will have to modify
code in all my content pages.

Can anybody suggest how can i specify a css file in master and inherit
that in all my content pages.

Thnx
Pushpadant

Jun 29 '06 #3

P: n/a
I have put the following in the master page

<head>
<LINK href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
But it will not reflect on the content page, because only the contents
in the
<asp:contentplaceholder
will be inherited on the content pages,

what now i do is add in the content page:

HtmlLink cssLink = new HtmlLink();
cssLink.Href = "StyleSheet.css";
cssLink.Attributes.Add("rel","stylesheet");
cssLink.Attributes.Add("type", "text/css");
Header.Controls.Add(cssLink);

but this i will have to write in all the content pages, is there any
way to avoid this code replication.

somehow content page cud get the link from Master page

Jun 30 '06 #4

P: n/a

I have created a common class, it has a func addCSS(htmlheader header),
now i call this function from all my pages passing header of the page
as parameter..

I this case if i want to use some other css page, will have to change
only at one place in the class.

Thnx for ur reponses.

Pushpadant

Jun 30 '06 #5

P: n/a
wrong. look at the resultant HTML source. you will see your style sheet
reference in there, with the way i proposed.

cheers

neil
Pushpadant wrote:
I have created a common class, it has a func addCSS(htmlheader header),
now i call this function from all my pages passing header of the page
as parameter..

I this case if i want to use some other css page, will have to change
only at one place in the class.

Thnx for ur reponses.

Pushpadant


Jun 30 '06 #6

P: n/a
In article <11**********************@75g2000cwc.googlegroups. com>,
pu********@gmail.com writes
<snip>
>Can anybody suggest how can i specify a css file in master and inherit
that in all my content pages.
Well, apart from the ways that others have suggested, which should all
work and be a lot easier than the way you have suggested, you could look
at using themes. If you specify a theme, and put the CSS file in the
appropriate theme folder, then the framework will include it in every
page for you. You don't need to do anything.

HTH

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

P: n/a

@Neil..

You were absolutely right...i tried ur method at the very
begining.....but it did not work....that was the only reason i
posted...but now it did seem to wrk....
i really cant guess y....
will try using theme some time later after i've got a working model.

Thnx for the help....

Jul 3 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.