 |
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
|
|
|
|
|

November 7th, 2009, 07:51 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 48
Thanks: 16
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 7th, 2009, 08:00 AM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 70
Thanks: 18
Thanked 1 Time in 1 Post
|
|
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.
|
|

November 7th, 2009, 08:19 AM
|
|
Registered User
|
|
Join Date: Oct 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 7th, 2009, 08:53 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

November 7th, 2009, 09:46 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 48
Thanks: 16
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 7th, 2009, 09:48 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

November 7th, 2009, 11:22 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 48
Thanks: 16
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 7th, 2009, 11:24 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 48
Thanks: 16
Thanked 0 Times in 0 Posts
|
|
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!
|
|
 |