Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Adding to the style of the Master page from a Content page

Reply
Thread Tools

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

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      08-18-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
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
Stan
Guest
Posts: n/a
 
      08-21-2008
On 18 Aug, 15:27, "Nathan Sokalski" <(E-Mail Removed)>
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
> (E-Mail Removed)://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

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
Adding to the style of the Master page from a Content page Nathan Sokalski ASP .Net 2 08-21-2008 09:13 AM
Missing Content Placeholder in nested master content page John ASP .Net 2 01-15-2008 11:48 AM
Master-Content in Asp.net - How to set individual Head for each content page Rolf Welskes ASP .Net 7 08-22-2006 02:47 PM
limit on number of content placeholders(which are editable in content pages) in master page nemesis.saurabh@gmail.com ASP .Net 0 05-25-2006 04:44 AM
seeking servlet "Master" keep getting "Master/servlet/Master" not found. Tomcat 5.0.25 Doug McCann Java 1 08-05-2004 09:16 PM



Advertisments