473,729 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To? Programmaticall y Set Theme For Master Page

Hello,

I have tried to programmaticall y set the theme for my master page by
putting code in a "Page_PreIn it" 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
programmaticall y set a theme for a master page?

Apr 17 '06 #1
1 8001
Try using a base class that inherits from System.Web.UI.P age 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(ob ject 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.Cookie s["selectedTh eme"] != null)
{
preferredTheme = Request.Cookies["selectedTh eme"].Value;

// Set the Theme.
switch (preferredTheme )
{
case "SmokeyBlue s":
this.Theme = "SmokeyBlue s";
break;
case "WisconsinAutum n":
this.Theme = "WisconsinAutum n";
break;
default:
this.Theme = "SmokeyBlue s";
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.Ident ity.Name
// within the current HttpContext as the key to store data. By
default,
// profiles are available only for authenticated users.

ProfileCommon pc = (ProfileCommon) HttpContext.Cur rent.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.Cookie s["selectedTh eme"] == 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("sel ectedTheme");
selectedTheme.V alue = preferredTheme;
Response.Cookie s.Add(selectedT heme);
selectedTheme.E xpires = DateTime.Now.Ad dYears(10);
}
}
}

#endregion

}// Page_PreInit

"Joey" <jo*********@to pscene.com> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.com.. .
Hello,

I have tried to programmaticall y set the theme for my master page by
putting code in a "Page_PreIn it" 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
programmaticall y 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
3508
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 attribute. This works for the content pages, but it doesn't seem able to apply the styles to the top master page even though I did set the master head tag to runat server. Is this by design? If so, what is the best way to apply styles to the top...
1
2296
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? Do I need to add the theme on the top of each page I create from this master page?
0
1714
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 please point me in the right direction to bind a theme to the treeview? The 'theme' tag is on the <%@ page %> directive... however neither my master page or ASCX files use this. They use <%Master%> and
7
1512
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 http://mcgeeky.blogspot.com
4
1508
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 Visual studio 2005) as the master page, the images appear correctly. However, the images do not appear when I am using a container file within a directory. Do I need to use links that aren't relative to the master page so that any content page...
5
20153
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 "background-image". In some aspx files this background image are lost. for example: background-image:url('../App_Themes/images/image2.gif '); Any solution for this?
0
1564
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 codification subsequently produces the required web-controls for a page based on whether the page is eg. in view or update mode, examination of the user's security permissions for certain fields, etc. In VS2003 our "Page Master" (to use the VS2005 term)...
0
1374
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 SkinID="recipient">fffff</asp:TableCell> </asp:TableRow>
6
3502
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, smaller ones, and referring to them in my HTML/ASP files on an as-needed basis. Essentially, I've organized things as: /default.asp
0
8927
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9289
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9210
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8159
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6026
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4798
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3242
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.