Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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 February 13th, 2011, 04:17 AM
Registered User
 
Join Date: Feb 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default CH 6 Problems

I am having a problem with chapter 6, user selected themes.

I can get the theme name in the drop down box to change from Monochrome to Dark Gray, but the theme does not change for me.

I have looked all over the forums and double checked my code with the fixes that were given to others, and I have also quadruple checked my code with what is in the book. I just cannot figure out where my issue is.

My code is as follows:

MasterPage:

Partial Class MasterPages_Frontend
Inherits System.Web.UI.MasterPage

Protected Sub ThemeList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ThemeList.SelectedIndexChanged
Dim preferredTheme As HttpCookie = New HttpCookie("PreferredTheme")
preferredTheme.Expires = DateTime.Now.AddMonths(3)
preferredTheme.Value = ThemeList.SelectedValue
Response.Cookies.Add(preferredTheme)
Response.Redirect(Request.Url.ToString())
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim selectedTheme As String = Page.Theme
Dim preferredTheme As HttpCookie = Request.Cookies.Get("PreferredTheme")
If preferredTheme IsNot Nothing Then
selectedTheme = preferredTheme.Value
End If
If Not String.IsNullOrEmpty(selectedTheme) AndAlso
ThemeList.Items.FindByValue(selectedTheme) IsNot Nothing Then
ThemeList.Items.FindByValue(selectedTheme).Selecte d = True
End If
End If
End Sub
End Class

BasePage:

Imports Microsoft.VisualBasic

Public Class BasePage
Inherits System.Web.UI.Page

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

If Me.Title = "Untitled Page" Or String.IsNullOrEmpty(Me.Title) Then
Throw New Exception("Page title cannot be ""Untitled Page"" or an empty string.")
End If
End Sub
End Class

If anything else is needed please let me know. This is getting pretty frustrating and I would like to get this fixed so I can complete the chapter.
 
Old February 13th, 2011, 06:28 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 there,

Looks like you missed the exercise on page 231 that shows you how to apply the theme by adding code to the central BasePage.

Your BasePage should then look like this:

Code:
 
Public Class BasePage
    Inherits System.Web.UI.Page
  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
      Page.Theme = preferredTheme.Value
    End If
  End Sub

  Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) _
            Handles Me.PreRender
    If Me.Title = "Untitled Page" Or String.IsNullOrEmpty(Me.Title) Then
      Throw New Exception("Page title cannot be ""Untitled Page"" or an empty string.")
    End If
  End Sub
End Class
Hope this helps,

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!
 
Old February 13th, 2011, 06:30 AM
Registered User
 
Join Date: Feb 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I did miss that. I read it as if it were stating that as example code, not code that should be written. Thank you.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ajax Problems ch. 27 gigs BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 0 September 24th, 2007 05:50 AM
Ch 7. Problems with Updating using GenericObject mercury7 BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 0 January 5th, 2007 10:37 AM
Problems width userviewer ch.12 compac BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 March 28th, 2005 10:07 AM
Problems with the editor example in ch 10 arne Beginning PHP 4 August 21st, 2004 02:24 PM
Problems with Ch. 18 example tomephillips BOOK: Beginning ASP 3.0 5 November 6th, 2003 08:25 AM





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