Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 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 January 27th, 2007, 08:52 PM
Authorized User
 
Join Date: Sep 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Theme Selector wont pick up other theme

Hey

I have created a theme selector that reads the themes in the App_Themes folder and displays them in a dropdown list on a web page.I want users to be able to select the theme they prefer and change the whole pages appearance
to that theme.

The default theme is working fine when the page is first loaded and displayed BUT when i try to change the theme by selecting a different theme from the dropdowlist,the page displays without any formatting.ie the other themes other than the default are not being picked up by the page.

The code for the theme selector user control is as follows:

 ddlThemes.DataSource = Helpers.GetThemes();
        ddlThemes.DataBind();
        ddlThemes.SelectedValue = this.Page.Theme;

The GetThemes method in the Helpers class is as follows:

  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");
                // get the array of themes folders under /app_themes
                string[] themes = Directory.GetDirectories(themesDirPath);
                for (int i = 0; i <= themes.Length - 1; i++)
                    themes[i] = Path.GetFileName(themes[i]);
                // cache the array with a dependency to the folder
                CacheDependency dep = new CacheDependency(themesDirPath);
                HttpContext.Current.Cache.Insert("SiteThemes", themes, dep);
                return themes;
            }

        }

I would greatly appreciate your help in resolving this problem

Thanks

Tawanda

 
Old January 28th, 2007, 01:12 AM
Authorized User
 
Join Date: Jan 2007
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had this problem before, when I copied info from the chapter-by-chapter code that somebody posted. I solved this by making sure every one of my pages inherited from the custom BasePage class. Meaning, my code-behind file, for my contact page for example, has the class statement written like this:

public partial class contact : BasePage

instead of just

public partial class contact : Page

It's the Basepage class that has that "OnPreInit" method that actually assigns the theme.
Hope this helps.
 
Old January 28th, 2007, 07:55 AM
Authorized User
 
Join Date: Sep 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Apparently my default.aspx actually inherits from the BasePage as you said but i still cant change the theme.Thanks for your time anyway.

 
Old January 28th, 2007, 08:28 PM
Authorized User
 
Join Date: Jan 2007
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry--I should have read your post more carefully. have you completely finished chapter 2? Well, look on page 40 and you'll see that your missing a line in that themeselector code you posted. it should be like this:

if (Globals.themeselectid.Length == 0) Globals.themeselectid = ddlThemes.UniqueID;
//then put the rest of your code:
ddlthemes.Datasource...;
...

If you don't already have that line, this probably also means you need that other snippet on page 40 that declares that global variable (the "themeselectid" in my example above. Use whatever name you like, just be consistent). That declaration is in Globals.cs in the App_Code folder.

 
Old May 4th, 2007, 07:52 AM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I think I have a similar problem to this. When trying to run the page I get the following compilation error:

 Compiler Error Message: CS1002: ; expected
 referring to line: public static string[] GetThemes()

I have gone back to the book and checked that I have done all the stages, but can only think I must have missed something.

Any help would be appreciated.
Thanks.
 
Old May 4th, 2007, 08:44 AM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

False alarm - I've sorted that bit now and moved onto my next head scratching moment.

Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception of get theme JasonF430 ASP.NET 2.0 Basics 0 April 16th, 2008 01:31 AM
theme selector from profile Maxxim BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 July 1st, 2007 10:35 PM
theme selector rav BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 February 12th, 2007 12:44 AM
page theme zhugeliang ASP.NET 2.0 Basics 1 January 9th, 2007 02:40 AM
theme selector inputcontrol highlight issue michaelitrn BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 September 10th, 2006 02:58 PM





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