Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
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 July 20th, 2010, 11:38 AM
Registered User
 
Join Date: Jul 2010
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 6 - Applying the User-Selected Themes

Hi,

I have just completed the Try It Out Exercise on page 231. However, when I view the Default.aspx page in the browser I receive the following error;


Server Error in '/Site' Application.
Theme 'Dark Grey' cannot be found in the application or global theme directories.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Theme 'Dark Grey' cannot be found in the application or global theme directories.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): Theme 'Dark Grey' cannot be found in the application or global theme directories.]
System.Web.Compilation.ThemeDirectoryCompiler.GetT hemeBuildResultType(String themeName) +934
System.Web.Compilation.ThemeDirectoryCompiler.GetT hemeBuildResultType(HttpContext context, String themeName) +73
System.Web.UI.Page.InitializeThemes() +8871714
System.Web.UI.Page.PerformPreInit() +38
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +328


Here is the code for my Frontend.master.vb

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

Here is the code for my BasePage.vb

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

Here is the code for my web.config page

<?xml version="1.0"?>

<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->

<configuration>
<system.web>
<pages theme="Monochrome" styleSheetTheme="Monochrome"></pages>
<compilation debug="false" strict="false" explicit="true" targetFramework="4.0" />
</system.web>

</configuration>




Thank you very much in advance!

Cheers

John B
 
Old July 20th, 2010, 12:14 PM
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,

The theme is called DarkGrey and not Dark Grey with a space. Once you make that change, you may need to delete your cookies in order for the page to run successfully. Alternatively, check out page 18 for error handling tips.

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!
 
Old July 20th, 2010, 01:23 PM
Registered User
 
Join Date: Jul 2010
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thank you for your quick reply Imar.

Clearing the browsers cookies has done the trick!

I am enjoying working through your book and find it clearly written and easy to follow as a newcomer to ASP.NET.


Cheers

JohnB
 
Old July 20th, 2010, 01:24 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

That's good to hear!

Have fun with the rest of the book.

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:
finkle (July 21st, 2010)
 
Old December 7th, 2010, 05:36 PM
Authorized User
 
Join Date: Dec 2007
Posts: 26
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi there,

I just got this error on chapter 6 page 228.
When I was running the try out exercise.

Error 1 C:\Users\giofranc\Documents\Visual Studio 2010\WebSites\WebSite3\MasterPages\Frontend.master .vb(21): error BC30451: 'selectedTheme' is not declared. It may be inaccessible due to its protection level.


Code:
 
rotectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load
IfNot Page.IsPostBack Then
Dim selectedTheme AsString = Page.Theme
Dim preferredTheme AsHttpCookie = Request.Cookies.Get("PreferredTheme")
If preferredTheme IsNotNothingThen
selectedTheme = preferredTheme.Value
EndIf
EndIf
IfNotString.IsNullOrEmpty(selectedTheme) AndAlso
ThemeList.Items.FindByValue(selectedTheme) IsNotNothingThen
ThemeList.Items.FindByValue(selectedTheme).selected = True
EndIf
EndSub

Last edited by gfranco; December 7th, 2010 at 05:38 PM.. Reason: typo error.
 
Old December 8th, 2010, 04:35 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,

You're closing off the first If statement too early. That way, the code that checks if selectedTheme is null or empty uses a variable which is defined in (and limited in scope to) an earlier If block and thus you get this error. If you look at the downloadable source for the book, you find the follow code in Frontend.master.vb:

Code:
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).Selected = True
    End If
  End If
End Sub
Notice how the check for String.IsNullOrEmpty(selectedTheme) is still part of the outer If check for Page.IsPostBack.

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 December 8th, 2010, 11:55 AM
Authorized User
 
Join Date: Dec 2007
Posts: 26
Thanks: 0
Thanked 1 Time in 1 Post
Default Thanks Imar

I will check and I will let you know.

Cheers,
GF





Similar Threads
Thread Thread Starter Forum Replies Last Post
Applying a user selected theme tariq BOOK: Beginning ASP.NET 4 : in C# and VB 4 July 4th, 2010 01:52 PM
Applying the User-Selected Theme Kerblamalot BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 January 29th, 2010 11:08 AM
(Chapter 6) applying user-selected theme in IE7 phoenixx ASP.NET 3.5 Basics 6 August 26th, 2008 09:49 AM
Applying themes programmatically in asp.net parimanamn ASP.NET 3.5 Professionals 1 May 23rd, 2008 06:53 AM
Chapter 5 Applying themes to Page Try it Out mcauliff BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 October 3rd, 2007 11:04 AM





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