p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   Changing Themes (http://p2p.wrox.com/showthread.php?t=43640)

notrosh June 7th, 2006 10:41 AM

Changing Themes
 
I am trying to let the user select themes. I have all the code in place but I am getting no results. Can anyone take a look and let me know what is wrong

thanks in advance


Imar June 7th, 2006 10:45 AM

Sure, if you post the code....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.

notrosh June 7th, 2006 11:40 AM

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


notrosh June 7th, 2006 12:19 PM

Hi Everyone thanks for the help.

However I figured out the problem

thanks,

zdavis


Imar June 7th, 2006 12:25 PM

Would you mind sharing how you fixed it? I am sure some future visitor will benefit from your answer....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004


All times are GMT -4. The time now is 07:31 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.