Loading the themes dynamically

I have just finish to apply themes dynamically and I want to share my experience.

1. I added a dropdown list to my Default.master file

2. I wrote theme class in to the App_Code folder

public class Theme{

private string _name;

public string Name

{

      get

            {

                  return _name;

             }

      set

            {

                  _name = value;

               }

   }

   public Theme(string name)

   {  

      Name = name;

   }

}

3. I created theme manager class

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Collections;

using System.Collections.Generic;

using System.IO;

/// <summary>

/// Summary description for ThemeManager

/// </summary>

public class ThemeManager

{

#region Theme-Related Method

public static List<Theme> GetThemes()

{

DirectoryInfo dInfo = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath("App_Themes"));

DirectoryInfo[] dArrInfo = dInfo.GetDirectories();

List<Theme> list = new List<Theme>();

foreach (DirectoryInfo sDirectory in dArrInfo)

{

Theme temp = new Theme(sDirectory.Name);

list.Add(temp);

}

return list;

}

#endregion

}

4. I added a object datasource to default.master

<asp:ObjectDataSource ID="ThemeDataSource" runat="server" SelectMethod="GetThemes" TypeName="ThemeManager" ></asp:ObjectDataSource>

5. Then I wrote the methods listed below

protected void lstTema_DataBound(object sender, EventArgs e)

{

lstTema.SelectedValue = Page.Theme;

}

protected void lstTema_SelectedIndexChanged(object sender, EventArgs e)

{

Session.Add("MyTheme", lstTema.SelectedValue);

Server.Transfer(Request.FilePath);

}

6. I created BasePage class

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

/// <summary>

/// Summary description for BasePage

/// </summary>

public class BasePage:System.Web.UI.Page

{

protected override void OnPreInit(EventArgs e)

{

base.OnPreInit(e);

if (Session["MyTheme"] == null)

{

Page.Theme = "Black";

}

else

{

Page.Theme = ((string)Session["MyTheme"]);

}

}

}

7.And after all I inherit all the pages from this class.

public partial class Default_aspx : BasePage

{

}

Thats All.