Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 7th, 2006, 10:41 AM
Authorized User
 
Join Date: May 2006
Location: fayetteville, Arkansas, USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to notrosh
Default 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

 
Old June 7th, 2006, 10:45 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Sure, if you post the code....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old June 7th, 2006, 11:40 AM
Authorized User
 
Join Date: May 2006
Location: fayetteville, Arkansas, USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to notrosh
Default

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

 
Old June 7th, 2006, 12:19 PM
Authorized User
 
Join Date: May 2006
Location: fayetteville, Arkansas, USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to notrosh
Default

Hi Everyone thanks for the help.

However I figured out the problem

thanks,

zdavis

 
Old June 7th, 2006, 12:25 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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




Similar Threads
Thread Thread Starter Forum Replies Last Post
Scrollbar in Themes. 99mary BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 March 28th, 2007 07:54 PM
Use Themes? the.pi.man ASP.NET 2.0 Basics 2 March 7th, 2007 08:44 AM
Themes bmains ASP.NET 2.0 Basics 2 August 2nd, 2004 08:48 AM





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