473,405 Members | 2,279 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,405 software developers and data experts.

How To? Programmatically Set Theme For Master Page

Hello,

I have tried to programmatically set the theme for my master page by
putting code in a "Page_PreInit" fuction in the master page's code
behind. However, when I set a breakpoint there and run the app, the
breakpoint is never hit. Of course my theme is not being applied.

The above procedure works fine for any content page, but obviously
doesn't work for my master page. So, how does one properly and
programmatically set a theme for a master page?

Apr 17 '06 #1
1 7982
Try using a base class that inherits from System.Web.UI.Page and of course
all content pages then inherit from the base class. Leave the code in the
Master alone. If your using Membership, Roles and Profiles you'll have to
use a cookie and the Profile to store the preferred Theme. Here's some code
from my base class to get started...

protected void Page_PreInit(object sender, EventArgs e)
{

#region Theme Selection...
// This region sets the Theme.
// A cookie is used to persist the selected Theme which reloads the
Theme
// for logged in users who would otherwise have to log in and
reselect
// their preferred Theme. The Theme is also stored in the Profile.
If the
// cookie is not found the preferred Theme is retrieved from the
Profile
// and the cookie is restored. The cookie also enables anonymous
users
// to persist a preferred Theme for a short period of time.

String preferredTheme;

// Get the selected theme from the cookie if the cookie is found.
if (Request.Cookies["selectedTheme"] != null)
{
preferredTheme = Request.Cookies["selectedTheme"].Value;

// Set the Theme.
switch (preferredTheme)
{
case "SmokeyBlues":
this.Theme = "SmokeyBlues";
break;
case "WisconsinAutumn":
this.Theme = "WisconsinAutumn";
break;
default:
this.Theme = "SmokeyBlues";
break;
}
}
else
{
// The cookie was not found so the Theme is retrieved from the
Profile.

// NOTE: Profile information is associated with the current user
based upon the
// identity of the user. By default, ASP.NET uses the
Page.User.Identity.Name
// within the current HttpContext as the key to store data. By
default,
// profiles are available only for authenticated users.

ProfileCommon pc = (ProfileCommon)HttpContext.Current.Profile;

if (pc.UserName != null)
{
preferredTheme = pc.LoggedInUser.SelectedTheme.ToString();
if (preferredTheme != null && preferredTheme.Length > 0)
{
//Set the preferred theme
this.Theme = preferredTheme;
}

if (Request.Cookies["selectedTheme"] == null)
{
// The Theme is only restored from the Profile when the
cookie
// is not found. Since we restored the Theme using the
Profile
// we also have to restore the cookie.
HttpCookie selectedTheme = new
HttpCookie("selectedTheme");
selectedTheme.Value = preferredTheme;
Response.Cookies.Add(selectedTheme);
selectedTheme.Expires = DateTime.Now.AddYears(10);
}
}
}

#endregion

}// Page_PreInit

"Joey" <jo*********@topscene.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Hello,

I have tried to programmatically set the theme for my master page by
putting code in a "Page_PreInit" fuction in the master page's code
behind. However, when I set a breakpoint there and run the app, the
breakpoint is never hit. Of course my theme is not being applied.

The above procedure works fine for any content page, but obviously
doesn't work for my master page. So, how does one properly and
programmatically set a theme for a master page?

Apr 17 '06 #2

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

Similar topics

7
by: sasquatch | last post by:
Hi, I've a a site with nested master pages and content pages. I tried using a theme with a stylesheet in the app_themes directory referencing it in the web.config file from a pages tag theme...
1
by: Miguel Dias Moura | last post by:
Hello, I am creating a master page for a web site. All pages created from this master page will use the same theme. However I am not able to add the theme in my master page. Why is that? ...
0
by: damiensawyer | last post by:
Hello all, I'm very new to all of this. I have a theme and a skin (the standard ones). I have a standard master page which is holding a custom ascx which has a treeview in it. Can someone...
7
by: McGeeky | last post by:
Hi. I have a page that is based on a master page. But how do I tell this page to use a CSS file using the LINK tag in the HEAD tag when the master page has this declaration in it? -- McGeeky...
4
by: JJ | last post by:
My master page contains various graphics that are referenced from the images folder. As long as the container pages are at the same level (ie. the top level looking at the solution explorer in...
5
by: 3Dfelix | last post by:
I have a problem when using a Master page file in diferent aspx files. Some of this aspx are in different places. I have see that the problem is with styles definition on master file, when use...
0
by: Kevin Frey | last post by:
We have a data-centric application where all of the "layout" for each data centric page is to be codified (ie. it is expressed in C# code rather than being expressed declaratively). This...
0
by: Jeff | last post by:
ASP.NET 2.0 I have problem with the markup and skin file below, this table isn't displayed. webpage <asp:Table ID="compose" SkinID="compose" runat="server"> <asp:TableRow> <asp:TableCell...
6
by: Homer J. Simpson | last post by:
Hi all, I have enough experience with HTML/classic ASP to get by, and I'm trying to learn ASP.NET. Traditionally, I've taken the habit of breaking out extra-long CSS files into multiple,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.