Here is all the code I used. If someone has a better way please let me know.
Classes
---------BasePage Class------------
namespace MB.NWA.UI
{
public class BasePage : System.Web.UI.Page
{
protected override void OnPreInit(EventArgs e)
{
string id = Globals.ThemesSelectorID;
if (id.Length > 0)
{
if (this.Request.Form["_EVENTTARGET"] == id && !string.IsNullOrEmpty(this.Request.Form[id]))
{
this.Theme = this.Request.Form[id];
this.Session["CurrentTheme"] = this.Theme;
}
else
{
if (this.Session["CurrentTheme"] != null)
this.Theme = this.Session["CurrentTheme"].ToString();
}
}
base.OnPreInit(e);
}
}
}
---------Globals Class---------
namespace MB.NWA
{
public static class Globals
{
public static string ThemesSelectorID = "";
}
----------Helpers Class----------
namespace MB.NWA.UI
{
public static class Helpers
{
public static string[] GetThemes()
{
if (HttpContext.Current.Cache["SiteThemes"] != null)
{
return (string[])HttpContext.Current.Cache["SiteThemes"];
}
else
{
string themesDirPath = HttpContext.Current.Server.MapPath("~/App_Themes");
string[] themes = Directory.GetDirectories(themesDirPath);
for (int i = 0; i<= themes.Length - 1; i++)
themes[i] = Path.GetFileName(themes[i]);
CacheDependency dep = new CacheDependency(themesDirPath);
HttpContext.Current.Cache.Insert("SiteThemes", themes, dep);
return themes;
}
}
}
}
----------User Control----------
namespace MB.NWA.UI.Controls
{
public partial class Controls_ThemeSelector : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (Globals.ThemesSelectorID.Length == 0)
Globals.ThemesSelectorID = ddlThemes.UniqueID;
ddlThemes.DataSource = Helpers.GetThemes();
ddlThemes.DataBind();
ddlThemes.SelectedValue = this.Page.Theme;
}
}
}
}
----------Default.aspx----------
public partial class _Default : MB.NWA.UI.BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
that is really just about all I have done. The themes show up in the dropdown box. However when i change them nothing happens. I have no compliation, syntax, or run-time errors. I also have the theme dropdown box property Autopostback = "true", any help would be greatly appreciated.
Thanks in advance
|