Adding to the style of the Master page from a Content page
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.
Re: Adding to the style of the Master page from a Content page
On 18 Aug, 15:27, "Nathan Sokalski" <nsokal...@kyledavidgroup.com>
> 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
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://
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
label1.Text = "This is what the bodyStyle looks like.";
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
<form id="form1" runat="server">
|All times are GMT. The time now is 11:40 AM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.