Page 1 of 1
App_Theme
Posted: Sat Aug 30, 2008 7:13 pm
by Tomgard
Is it possible to tie an application theme to a particular user or user group?
I have a lot of B2B customers and I would like use their logo/color scheme during their shopping session.
Re: App_Theme
Posted: Mon Sep 01, 2008 5:28 am
by mazhar
Well ASP.NET provides ways to change the theme through code. For this you have to set the Page.Theme property in the Page_PreInIt event handler like below
Code: Select all
protected void Page_PreInit(object sender, EventArgs e)
{
Page.Theme = "theme name";
}
You can give a try in your pages by first checking the user group or any other criteria for which you want to change the theme and then set theme accordingly.
Re: App_Theme
Posted: Tue Apr 28, 2009 10:19 pm
by bemara579
You can also put this in your Global.asax (notice how I am using the affiliate mobile number field to store the theme to avoid messing with the database schema):
Code: Select all
// this event is executed for every page request
// and is run before the PreInit event. Therefore we
// can use it to set the theme and master for every page
protected void Application_PreRequestHandlerExecute(object sender, System.EventArgs e)
{
// cast the current handler to a page object
Page page = HttpContext.Current.Handler as Page;
if (page != null)
{
// add an event handler for the PreInit event (the master page needs to be set there)
page.PreInit += new EventHandler(Custom_PreInit);
}
}
void Custom_PreInit(object sender, EventArgs e)
{
// cast the current handler to a page object
Page page = HttpContext.Current.Handler as Page;
if (page != null)
{
if (!Request.FilePath.StartsWith("/Admin/") &&
Token.Instance.User.Affiliate != null && Token.Instance.User.Affiliate.MobileNumber != String.Empty)
page.Theme = Token.Instance.User.Affiliate.MobileNumber;
}
}