Click here to Skip to main content
Click here to Skip to main content

Enable Theming using Cookies

, 14 Aug 2006
Rate this:
Please Sign up or sign in to vote.
Save User Theming Choice in Cookie

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

License

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

Share

About the Author

DevZu

United States United States
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 14 Aug 2006
Article Copyright 2006 by DevZu
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid