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 August 20th, 2008, 12:51 PM
Registered User
 
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 6 User-Selected Theme Question

My question refers to the section in Chapter 6 on Themes, in particular pages pages 222-228.

I've been making my way through the book, building the PlanetWrox website as I go, using the C# examples. Once I got to the part on Themes and cookies, I thought I might play around with it to see what would happen if I got rid of the cookie or let it expire. (Setting the lifespan of the cookie to 1 minute vs. 3 months for example.)

Unfortunately once the cookie expires, the site stops working. I get the following error at run time in the browser(with line 25 highlighted in red):
----------------------------
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 23: HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");
Line 24:
*Line 25: if (preferredTheme.Value != null)
Line 26: {
Line 27: Page.Theme = preferredTheme.Value;


Source File: c:\BegASPNET\Site\App_Code\BasePage.cs Line: 25

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   BasePage.Page_PreInit(Object sender, EventArgs e) in c:\BegASPNET\Site\App_Code\BasePage.cs:25
   System.Web.UI.Page.OnPreInit(EventArgs e) +75
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1344
--------------------------

Any ideas on how to fix this other than taking out the code in the Page_PreInit Sub from pg 227 and recompiling? Once I do that, I can safely add the Page_PreInit code back in, and it works again. Guess I'm just wondering how to make this work if a cookie doesn't already exist or if it expired.

Thanks,
Jason



 
Old August 20th, 2008, 03:43 PM
Registered User
 
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Never mind. I figured out my problem. I was using "preferredTheme.Value != null" rather than "preferredTheme != null" in the code on pg 277.

 
Old August 21st, 2008, 03:45 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Easy to make such a mistake.... ;)

Glad you got it working...


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
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 6 pps 226-228 User Selected Theme Featheriver BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 20th, 2011 07:08 AM
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
(Chapter 6) applying user-selected theme in IE7 phoenixx ASP.NET 3.5 Basics 6 August 26th, 2008 09:49 AM
VB.net 2005 User theme datagrid alex1985 Visual Studio 2005 7 September 11th, 2007 01:34 PM
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.