p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 7th, 2009, 07:51 AM
Authorized User
Points: 106, Level: 2
Points: 106, Level: 2 Points: 106, Level: 2 Points: 106, Level: 2
Activity: 27%
Activity: 27% Activity: 27% Activity: 27%
 
Join Date: Apr 2009
Posts: 14
Thanks: 6
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old November 7th, 2009, 08:00 AM
Authorized User
Points: 208, Level: 4
Points: 208, Level: 4 Points: 208, Level: 4 Points: 208, Level: 4
Activity: 42%
Activity: 42% Activity: 42% Activity: 42%
 
Join Date: Jun 2009
Posts: 48
Thanks: 14
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old November 7th, 2009, 08:19 AM
Registered User
Points: 11, Level: 1
Points: 11, Level: 1 Points: 11, Level: 1 Points: 11, Level: 1
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old November 7th, 2009, 08:53 AM
Imar's Avatar
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 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
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004

Did this post help you? Click the button to show your appreciation!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
robbaralla (November 7th, 2009)
  #5 (permalink)  
Old November 7th, 2009, 09:46 AM
Authorized User
Points: 106, Level: 2
Points: 106, Level: 2 Points: 106, Level: 2 Points: 106, Level: 2
Activity: 27%
Activity: 27% Activity: 27% Activity: 27%
 
Join Date: Apr 2009
Posts: 14
Thanks: 6
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old November 7th, 2009, 09:48 AM
Imar's Avatar
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 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
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004

Did this post help you? Click the button to show your appreciation!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
robbaralla (November 7th, 2009)
  #7 (permalink)  
Old November 7th, 2009, 11:22 AM
Authorized User
Points: 106, Level: 2
Points: 106, Level: 2 Points: 106, Level: 2 Points: 106, Level: 2
Activity: 27%
Activity: 27% Activity: 27% Activity: 27%
 
Join Date: Apr 2009
Posts: 14
Thanks: 6
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old November 7th, 2009, 11:24 AM
Authorized User
Points: 106, Level: 2
Points: 106, Level: 2 Points: 106, Level: 2 Points: 106, Level: 2
Activity: 27%
Activity: 27% Activity: 27% Activity: 27%
 
Join Date: Apr 2009
Posts: 14
Thanks: 6
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 03: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 02:50 AM
(Chapter 6) applying user-selected theme in IE7 phoenixx ASP.NET 3.5 Basics 6 August 26th, 2008 10: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 04: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 09:44 AM



All times are GMT -4. The time now is 08:20 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc