473,387 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Master Page prevents using style sheets?

JT
Hi,

I have done a fair amount of style editing inline in ASP. I'm now
using VS 2005 with a standard web project (not Web Application
Project). This is my first foray into CSS in a style sheet and also my
first true attempt at using master pages. I tried setting up a style
sheet with a simple setting to float an image to the right and it had
no effect on the image.

Then, I tried putting the style code in my ASPX file as such,

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile =
"~/MyMaster.master" CodeFile="ProductDetails.aspx.cs"
Inherits="ProductDetails" %>
<style type="text/css">
img
{
float:right;
border:1px dotted black;
margin:0px 0px 15px 20px;
}
</style>

<asp:Content ID="Content1" ContentPlaceHolderID="cphMain"
Runat="Server">
<asp:Panel ID="pnlProduct" runat="server" Height="50px"
Style="z-index: 100;
position: relative;" >
<asp:Label ID="lblManufacturer" runat="server" Font-Bold="True"
Font-Underline="True"
Style="z-index: 101; position: relative;"
Text="Manufacturer" Font-Size="X-Large"></asp:Label>
<br />
<asp:Label ID="lblProductName" runat="server" Font-Bold="True"
Font-Underline="True"
Style="z-index: 100; position: relative;" Text="Product
Name"></asp:Label>
<br />
</asp:Panel>
<asp:Panel ID="pnlDescription" runat="server" Height="50px"
Style="z-index: 102;
position: relative; text-align: left" Width="873px">
<asp:Literal ID="ltrDescription" runat="server"></asp:Literal>
</asp:Panel>
</asp:Content>

It complained that "Content is not supported outside 'script' or
'asp:content' regions".

I tried moving the style setting inside the asp:content region and it
complained that "Element 'style' cannot be nested within element 'td'".
This is because my ContentPlaceHolder is inside a table in my master
page. As of yet, I can't get the desired layout without doing that.

I created a new page, ProductDetails2.aspx, as a stand-alone Web Form
page, inserted the style element into the head element and now it
works, but I don't have the menu and other standard page formatting
that was contained in the master page. So my questions are:

1. What do I need to do to make my style settings work with pages that
reference my master page? Do I need to take away all formatting that
would require the style element to be nested?

2. Do I need to reference my stylesheet like you would reference a DLL?

3. Does including a stylesheet in the solution/project automatically
apply it to all pages in the project?

Thanks for your help.

Sep 5 '06 #1
8 6646
Rob
JT,

Your styles should appear in the master page. By using master pages the
individual "sub pages" do not have direct access to the <HTML><HEAD><BODY>
tags (by default).

You can add a public property/method to the master page that provides access
to the head element though. More or less in the master's .cs file add:

public void AddStyles(string styles)
{
Literal1.Text = styles;
}

In the master's markup add a literal control in the the <HEAD></HEADarea.

In the sub page's markup add the following declaration (forces Page.Master
to be strongly typed)
<%@ MasterType VirtualPath="~/masters/SourcePage.master" %>
And in the sub page's onload you can do something like:

protected void Page_Load(object sender, EventArgs e)
{
Page.Master.AddStyles("<style>img {float:right;border:1px;} </style>");
}

Regards,

Rob

"JT" <jt@onemain.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Hi,

I have done a fair amount of style editing inline in ASP. I'm now
using VS 2005 with a standard web project (not Web Application
Project). This is my first foray into CSS in a style sheet and also my
first true attempt at using master pages. I tried setting up a style
sheet with a simple setting to float an image to the right and it had
no effect on the image.

Then, I tried putting the style code in my ASPX file as such,

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile =
"~/MyMaster.master" CodeFile="ProductDetails.aspx.cs"
Inherits="ProductDetails" %>
<style type="text/css">
img
{
float:right;
border:1px dotted black;
margin:0px 0px 15px 20px;
}
</style>

<asp:Content ID="Content1" ContentPlaceHolderID="cphMain"
Runat="Server">
<asp:Panel ID="pnlProduct" runat="server" Height="50px"
Style="z-index: 100;
position: relative;" >
<asp:Label ID="lblManufacturer" runat="server" Font-Bold="True"
Font-Underline="True"
Style="z-index: 101; position: relative;"
Text="Manufacturer" Font-Size="X-Large"></asp:Label>
<br />
<asp:Label ID="lblProductName" runat="server" Font-Bold="True"
Font-Underline="True"
Style="z-index: 100; position: relative;" Text="Product
Name"></asp:Label>
<br />
</asp:Panel>
<asp:Panel ID="pnlDescription" runat="server" Height="50px"
Style="z-index: 102;
position: relative; text-align: left" Width="873px">
<asp:Literal ID="ltrDescription" runat="server"></asp:Literal>
</asp:Panel>
</asp:Content>

It complained that "Content is not supported outside 'script' or
'asp:content' regions".

I tried moving the style setting inside the asp:content region and it
complained that "Element 'style' cannot be nested within element 'td'".
This is because my ContentPlaceHolder is inside a table in my master
page. As of yet, I can't get the desired layout without doing that.

I created a new page, ProductDetails2.aspx, as a stand-alone Web Form
page, inserted the style element into the head element and now it
works, but I don't have the menu and other standard page formatting
that was contained in the master page. So my questions are:

1. What do I need to do to make my style settings work with pages that
reference my master page? Do I need to take away all formatting that
would require the style element to be nested?

2. Do I need to reference my stylesheet like you would reference a DLL?

3. Does including a stylesheet in the solution/project automatically
apply it to all pages in the project?

Thanks for your help.

Sep 5 '06 #2
JT
Sweet! I'll have to explore that.

I just found something in an old HTML book of mine concerning css. I
was making a newbie error. I needed to put the following into my
master page's <head></headsection:

<head runat="server">
<style type = "text/css">
<!--
@import url(MyStyleSheet.css);
-->
</style>
</head>

That got my styles going for the site. But I'm thinking I'll have to
use your suggestion to override that in specific pages, correct?

Thanks for the quick response! I'm sure my eyes will be opened once I
realize the power of a css file. No more repeated inline code or
include files. I still prefer WinForms apps.

JT
Rob wrote:
JT,

Your styles should appear in the master page. By using master pages the
individual "sub pages" do not have direct access to the <HTML><HEAD><BODY>
tags (by default).

You can add a public property/method to the master page that provides access
to the head element though. More or less in the master's .cs file add:

public void AddStyles(string styles)
{
Literal1.Text = styles;
}

In the master's markup add a literal control in the the <HEAD></HEADarea.

In the sub page's markup add the following declaration (forces Page.Master
to be strongly typed)
<%@ MasterType VirtualPath="~/masters/SourcePage.master" %>
And in the sub page's onload you can do something like:

protected void Page_Load(object sender, EventArgs e)
{
Page.Master.AddStyles("<style>img {float:right;border:1px;} </style>");
}

Regards,

Rob

"JT" <jt@onemain.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Hi,

I have done a fair amount of style editing inline in ASP. I'm now
using VS 2005 with a standard web project (not Web Application
Project). This is my first foray into CSS in a style sheet and also my
first true attempt at using master pages. I tried setting up a style
sheet with a simple setting to float an image to the right and it had
no effect on the image.

Then, I tried putting the style code in my ASPX file as such,

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile =
"~/MyMaster.master" CodeFile="ProductDetails.aspx.cs"
Inherits="ProductDetails" %>
<style type="text/css">
img
{
float:right;
border:1px dotted black;
margin:0px 0px 15px 20px;
}
</style>

<asp:Content ID="Content1" ContentPlaceHolderID="cphMain"
Runat="Server">
<asp:Panel ID="pnlProduct" runat="server" Height="50px"
Style="z-index: 100;
position: relative;" >
<asp:Label ID="lblManufacturer" runat="server" Font-Bold="True"
Font-Underline="True"
Style="z-index: 101; position: relative;"
Text="Manufacturer" Font-Size="X-Large"></asp:Label>
<br />
<asp:Label ID="lblProductName" runat="server" Font-Bold="True"
Font-Underline="True"
Style="z-index: 100; position: relative;" Text="Product
Name"></asp:Label>
<br />
</asp:Panel>
<asp:Panel ID="pnlDescription" runat="server" Height="50px"
Style="z-index: 102;
position: relative; text-align: left" Width="873px">
<asp:Literal ID="ltrDescription" runat="server"></asp:Literal>
</asp:Panel>
</asp:Content>

It complained that "Content is not supported outside 'script' or
'asp:content' regions".

I tried moving the style setting inside the asp:content region and it
complained that "Element 'style' cannot be nested within element 'td'".
This is because my ContentPlaceHolder is inside a table in my master
page. As of yet, I can't get the desired layout without doing that.

I created a new page, ProductDetails2.aspx, as a stand-alone Web Form
page, inserted the style element into the head element and now it
works, but I don't have the menu and other standard page formatting
that was contained in the master page. So my questions are:

1. What do I need to do to make my style settings work with pages that
reference my master page? Do I need to take away all formatting that
would require the style element to be nested?

2. Do I need to reference my stylesheet like you would reference a DLL?

3. Does including a stylesheet in the solution/project automatically
apply it to all pages in the project?

Thanks for your help.
Sep 5 '06 #3
"Rob" <rmacfadyen_at_gmail.comwrote in message
news:Ob**************@TK2MSFTNGP03.phx.gbl...
By using master pages the individual "sub pages" do not have direct access
to the <HTML><HEAD><BODYtags (by default).
Yes they do - just add runat="server" to the tag e.g.

<header runat="server">
....
....
....
</head>

Then, in your codefile, you can do something like:

Style objStyle = new Style();
objStyle.ForeColor = System.Drawing.Color.Yellow;
Header.StyleSheet.CreateStyleRule(objStyle, null, "td");
Sep 5 '06 #4
Furthermore, to help clarify Rob's misunderstanding there are new classes
unique to the head. Start with the following search term and look through
the other related classes listed in the tree that is displayed with MSDN
documentation.

htmlhead class site:msdn2.microsoft.com

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:uZ**************@TK2MSFTNGP04.phx.gbl...
"Rob" <rmacfadyen_at_gmail.comwrote in message
news:Ob**************@TK2MSFTNGP03.phx.gbl...
>By using master pages the individual "sub pages" do not have direct
access to the <HTML><HEAD><BODYtags (by default).

Yes they do - just add runat="server" to the tag e.g.

<header runat="server">
...
...
...
</head>

Then, in your codefile, you can do something like:

Style objStyle = new Style();
objStyle.ForeColor = System.Drawing.Color.Yellow;
Header.StyleSheet.CreateStyleRule(objStyle, null, "td");


Sep 6 '06 #5
Whoopsie :)

I am of course massively incorrect. As pointed out:

this.Header.StyleSheet.CreateStyleRule(...)

is exactly what you're looking for.

I guess I was just to impressed with strongly typed master pages.

Thanx to Mark Rae and Clinton for keeping things straight :)

Regards,

Rob MacFadyen
Sep 6 '06 #6
I've eaten more crow than you'll ever know ;-)

<%= Clinton Gallagher

"Rob MacFadyen" <rmacfadyen_at_gmail.comwrote in message
news:uu**************@TK2MSFTNGP03.phx.gbl...
Whoopsie :)

I am of course massively incorrect. As pointed out:

this.Header.StyleSheet.CreateStyleRule(...)

is exactly what you're looking for.

I guess I was just to impressed with strongly typed master pages.

Thanx to Mark Rae and Clinton for keeping things straight :)

Regards,

Rob MacFadyen

Sep 6 '06 #7
"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.comwro te in message
news:e7**************@TK2MSFTNGP04.phx.gbl...
I've eaten more crow than you'll ever know ;-)
Likewise... :-)
Sep 7 '06 #8
JT
I like mine with peppercorn sauce. Mmmm... mmmm!

Thanks again for the help!

Mark Rae wrote:
"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.comwro te in message
news:e7**************@TK2MSFTNGP04.phx.gbl...
I've eaten more crow than you'll ever know ;-)

Likewise... :-)
Sep 8 '06 #9

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

Similar topics

0
by: Andrea | last post by:
Hi everyone. I'm working on a navigation menu (in a frameset) that I want to set the "active" link to black (the link that corresponds to the page displayed in the right side of the frame) to...
3
by: Paul | last post by:
I found a great site for CSS tempaltes, http://blog.html.it/layoutgala/ . I downloaded them, and played around with them. Then I tried to use the template in as ASP.Net MasterPage, but everything...
1
by: Sam | last post by:
Attached I am sending 2 URL's from MSFT ASP.net Quick Start Tutorial Web Site. 1) Run it URL: http://www.asp.net/QuickStart/aspnet/samples/data/GridViewMasterDetai... 2) View Source URL:...
2
by: Neil Steventon | last post by:
Hi , I puzzled on how to layout my website. I have a master page with a style sheet defined in the top. Then I have the various pages using this master page, I would however for cetain pages...
2
by: Velochicdunord | last post by:
Hi everyone, I've been lurking for two weeks now, learning as much as I can about CSS. Still in the bottom half of the curve, but looking to figure out how to do more stuff. I've just tossed...
1
by: Kat | last post by:
I have a master page, with a reference to a style sheet in the header, as usual: <link href="Styles.css" type="text/css" rel="stylesheet" /> I have a content page, with a label on it: ...
1
by: rameshpleasure | last post by:
how write code in masterpage contentholder html code without using runat=server. please help
1
by: ravichobey | last post by:
Hi all, I am currently writing a C based CGI scripting.When i am not using any style sheets in my program,it compiles and executes properly. But when i am using style sheets,it is giving...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.