PC Review


Reply
Thread Tools Rate Thread

Adding to the style of the Master page from a Content page

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      18th Aug 2008
I have a content page from which I need to add a style rule to be used by
the page. Since content pages only have the content tags, I obviously need
to edit the Master page's style using code. I am assuming this will be done
in the PreInit eventhandler, but i cannot find the right way to do this. Can
someone help me? Thanks.

Nathan Sokalski
(E-Mail Removed)
http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      18th Aug 2008
I tried that, but I could not figure out how to add the CSS properties I
wanted to the Style object (such as padding), since it doesn't have
properties for them, and I couldn't figure out what property to use. Can you
tell me how to set CSS properties that the Style object does not have
properties for? Thanks.

"Mark Rae [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> "Nathan Sokalski" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> Can someone help me?

>
> protected void Page_Load(object sender, EventArgs e)
> {
> Style objStyle = new Style();
> objStyle.ForeColor = System.Drawing.Color.Navy;
> objStyle.BackColor = System.Drawing.Color.LightGray;
> this.Header.StyleSheet.CreateStyleRule(objStyle, null, "body");
> }
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
Stan
Guest
Posts: n/a
 
      21st Aug 2008
On 18 Aug, 15:27, "Nathan Sokalski" <nsokal...@kyledavidgroup.com>
wrote:
> I have a content page from which I need to add a style rule to be used by
> the page. Since content pages only have the content tags, I obviously need
> to edit the Master page's style using code. I am assuming this will be done
> in the PreInit eventhandler, but i cannot find the right way to do this. Can
> someone help me? Thanks.
>
> Nathan Sokalski
> njsokal...@hotmail.comhttp://www.nathansokalski.com/


hi Nathan
It depends on which version of Framework you are working with. With
version 3.5 MasterPages have a ContentPlaceholder in the Header
section so would make your task it very simple. With earlier versions
you have to do it programmatically using the Header property of the
page. The following example is from the Class library help files (note
that it works just as well with content pages):

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

void Page_Load(object sender, EventArgs e)
{
if (Page.Header != null)
{
// Create a Style object for the <body> section of the Web page.
Style bodyStyle = new Style();

bodyStyle.ForeColor = System.Drawing.Color.Blue;
bodyStyle.BackColor = System.Drawing.Color.LightGray;

// Add the style to the header of the current page.
Page.Header.StyleSheet.CreateStyleRule(bodyStyle, this, "BODY");

// Add text to the label2 control to see the style rules applied
to it.
label1.Text = "This is what the bodyStyle looks like.";
}
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
<title>IStyleSheet Example</title>
</head>
<body>
<form id="form1" runat="server">
<h1>IStyleSheet Example</h1>
<asp:Label
id="label1"
runat="server">
</asp:Label>
</form>
</body>
</html>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a public property on a master page visible to a content page Ex glider pilot Microsoft ASP .NET 1 25th May 2008 07:12 PM
Dynamically program User controls in a Master page from a content page Dinu Microsoft ASP .NET 1 31st Jul 2007 12:56 PM
content page subscriber to master page event doesn't update on 2nd postback Managed Code Microsoft ASP .NET 0 27th Jul 2006 05:22 PM
Setting the Page Title using local resources for a content page in a master page Laith Zraikat Microsoft ASP .NET 3 6th Jul 2006 02:23 AM
Master Page Control as Content Page DataSource Select Parameter in 2.0 David Microsoft ASP .NET 0 4th Jun 2005 05:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:51 AM.