Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 November 7th, 2009, 07:51 AM
Authorized User
 
Join Date: Apr 2009
Posts: 48
Thanks: 16
Thanked 0 Times in 0 Posts
Default chapter 6 p226 preferred theme in basepage

Hi Imar,

I noticed that in the try it out on p222 in step 5, a check is made to see if the selectedTheme is still present in the lstPreferredTheme. So that an outdated theme in the cookie is ignored.

In the next try it out however, in step 1 this check is not made. So requesting the PreferredTheme cookie in case there would be an outdated theme in it, gives an error- At least that is what happened to me when I first made another theme and later threw it away.
I solved this by commenting out the theme/setting in the PreInit event in the basepage, not a very lasting and elegant solution... What would a proper solution be ?

Thanks,
Robin
 
Old November 7th, 2009, 08:00 AM
Authorized User
 
Join Date: Jun 2009
Posts: 70
Thanks: 18
Thanked 1 Time in 1 Post
Default

At a guess, this is a part of the book where you should ave the default theme set in web.config
Code:
         <pages theme="Monochrome">
asp.net then sees that there is no cookie set - and looks for the default theme in web.config.
 
Old November 7th, 2009, 08:19 AM
Registered User
 
Join Date: Oct 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey robbaralla,

As far as i know the code to check is made in the MasterPage.Master Page_Load. So the code will always run on the pages that rely on that masterpage.

Greets, Chris
 
Old November 7th, 2009, 08:53 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Robin,

You could look into the App_Themes folder and see if there is a folder with the name of the theme from the cookie. The following code is untested, but should do the trick:

Code:
 
Private Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) _
         Handles Me.PreInit
  Dim preferredTheme As HttpCookie = Request.Cookies.Get("PreferredTheme")
  If preferredTheme IsNot Nothing Then
    Dim rootThemeFolder As String = Server.MapPath("~/App_Themes")
    Dim themes As DirectoryInfo = New DirectoryInfo(rootThemeFolder)
    Dim themeFolder = (From folder In themes.GetDirectories() _
                      Where folder.Name.ToLower() = preferredTheme.Value.ToLower() _
                      Select folder).FirstOrDefault()
    If themeFolder IsNot Nothing Then
      Page.Theme = preferredTheme.Value
    End If
  End If
End Sub
This code first gets the physical location of the App_Themes folder using Server.MapPath. In then creates a DirectoryInfo object which is used in a LINQ query to get all sub folders, FirstOrDefault returns either a DirectoryInfo when the theme folderr exists or Nothing otherwise. In the former case, you know the theme is there and you can successfully set the Theme proeprty.

Hope this helps. Let me know if you prefer the C# version instead.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
robbaralla (November 7th, 2009)
 
Old November 7th, 2009, 09:46 AM
Authorized User
 
Join Date: Apr 2009
Posts: 48
Thanks: 16
Thanked 0 Times in 0 Posts
Thumbs up Bedankt Imar! Exactly what I meant.

That looks like the solution to me!, I'll try it out and if it doesn't solve the problem I'll get back.
Actually I do prefer C#, but with all the examples in your book I'll be able to translate it, no prob.

(the thanks button on yuor reply was disabled)
Thanks,
Robin
 
Old November 7th, 2009, 09:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default Graag gedaan!

Code:
(the thanks button on yuor reply was disabled)
The one in my signature or the real one below the mssage?

Good luck with the translation; let me know if you need more help.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
robbaralla (November 7th, 2009)
 
Old November 7th, 2009, 11:22 AM
Authorized User
 
Join Date: Apr 2009
Posts: 48
Thanks: 16
Thanked 0 Times in 0 Posts
Default thanks button

no the thumb icon on the message doesn't seem to work. Hovering over it doesn't change the cursor.

The code seems to work fine. The only thing was that the using statements on top had to be adapted;
using System.IO;
using System.Linq;
had to be added otherwise the DirectoryInfo and GetDirectories don't work.

Thanks again,

Robin
 
Old November 7th, 2009, 11:24 AM
Authorized User
 
Join Date: Apr 2009
Posts: 48
Thanks: 16
Thanked 0 Times in 0 Posts
Default ok I'm getting a bit silly here

I had to look at least twice to see that the icon in your signature is just a reference to the real icon, so never mind!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 18: Unable to see the site THEME locochinoloco BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 September 18th, 2008 02:35 AM
BasePage Code for VB (Chapter 6) justinjones06 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 September 15th, 2008 01:50 AM
(Chapter 6) applying user-selected theme in IE7 phoenixx ASP.NET 3.5 Basics 6 August 26th, 2008 09:49 AM
Chapter 6 User-Selected Theme Question jabo2099 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 August 21st, 2008 03:45 AM
Theme Selector wont pick up other theme Tawanda BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 May 4th, 2007 08:44 AM





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