Introduction
In converting my application to .Net 2.0, I wanted to include theme. But I asked myself how I change the theme in sub pages. I have a master page, but I wanted to be able to save the theme the user selected somewhere also. So I decided to use and create a Base Class file which inherits the System.Web.UI.Page. So the tasks is let the user change a theme on my website and save the choice in a cookie. So next time they come back, the theme they choose will be there.
Base Class:
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
String ThemeName;
if (Master != null)
{
_masterPageOrg = Page.MasterPageFile.ToString();
}
if (Request.Cookies["MyThemes"] != null)
{
ThemeName = Request.Cookies["MyThemes"].Value;
}
else
{
return;
}
switch (ThemeName)
{
case "Green":
Page.Theme = "Green";
break;
case "Orange":
Page.Theme = "Orange";
break;
case "Purple":
Page.Theme = "Purple";
break;
case "Blue":
Page.Theme = "Blue";
break;
case "Red":
Page.Theme = "Red";
break;
case "Yellow":
Page.Theme = "Yellow";
break;
}
}
Master Page Code:
SelTheme.Value = "Orange";
SelTheme.Expires = DateTime.Now.AddMonths(12);
if (Response.Cookies["MyThemes"] == null)
{
Response.Cookies.Add(SelTheme);
}
else
{
Response.Cookies.Remove("MyThemes");
Response.Cookies.Add(SelTheme);
}
View Source Code
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here