Wrox Programmer 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 Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 30th, 2009, 08:17 PM
Authorized User
Points: 81, Level: 1
Points: 81, Level: 1 Points: 81, Level: 1 Points: 81, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Default Chapter 7 errors

Hi,

I hope this is not asking too much for resolution.

I've added the CssClasses mentioned in page 250, then changed the properties mentioned in step #3. Warning have popped-up saying "The class or CssClass value is not defined" for each CssClass below:

Code:
 
<div id="PageWrapper"> </div>
<div id="Header"><a class="HeaderLink" href="~/" runat="server"> </a></div>
<div id="MenuWrapper">
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" 
Orientation="Horizontal" StaticEnableDefaultPopOutImage="False">
<StaticSelectedStyle CssClass="StaticSelectedStyle" />
<StaticMenuItemStyle CssClass="StaticMenuItemStyle" />
<DynamicHoverStyle CssClass="DynamicHoverStyle" />
<DynamicMenuItemStyle CssClass="DynamicMenuItemStyle" />
<StaticHoverStyle CssClass="StaticHoverStyle" />
</asp:Menu> 
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" 
ShowStartingNode="False" />
</div>
Also, another same warning for the "HeaderLink" of the Header ID above.

I can run the web app fine despite the errors, but when I try to access any of the submenu, it throws this very friendly error:


Server Error in '/' Application.

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 9: selectedTheme = preferredTheme.ValueLine 10: End IfLine 11: If lstPreferredTheme.Items.FindByValue(selectedTheme) IsNot Nothing ThenLine 12: lstPreferredTheme.Items.FindByValue(selectedTheme) .Selected = TrueLine 13: End If
Source File: C:\PracticePrograms\MrsHomeLoans\MrsHomeLoans\Mast er\Master.Master.vb Line: 11

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] MrsHomeLoans.Master.Page_Load(Object sender, EventArgs e) in C:\PracticePrograms\MrsHomeLoans\MrsHomeLoans\Mast er\Master.Master.vb:11 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Control.LoadRecursive() +141 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint


It is strange because when I created a test webform and replace my sitemap values with that webform as shown below, the page is diplayed without the error above.

Below is my sitemap values created as per page 243.

Code:
 
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/" title="Home" description="My Home">
<siteMapNode url="~/Default.aspx" title="Home" description="Go to the homepage" />
 
<siteMapNode url="~/Reviews/Default.aspx" title="Reviews" description="Reviews published on this site">
<siteMapNode url="~/Reviews/AllByGenre.aspx" title="By Genre" description="All reviews grouped by genre" />
<siteMapNode url="~/Reviews/All.aspx" title="All reviews" description="All reviews" />
</siteMapNode>
 
<siteMapNode url="~/About/Default.aspx" title="About" description="About this site">
<siteMapNode url="~/About/Contact.aspx" title="Contact Us" description="Contact Us" />
<siteMapNode url="~/About/AboutUs.aspx" title="About Us" description="About Us" />
</siteMapNode>
 
<siteMapNode url="~/Login.aspx" title="Login" description="Log in to this web site" />
</siteMapNode> 
 
</siteMap>

When I debug the app, I get the "monochrome" value in LINE 11. The name of my dropdown listbox is lstPreferredTheme as per the book.

Thanks

p.s. I've copied your MasterPage code-behind and pasted it on my own, but I got the same error "NullReferenceException was unhandled by the user code" on the same line that my code is getting before.

Thanks

Last edited by janilane; April 30th, 2009 at 10:58 PM. Reason: Added a few comments
Reply With Quote
  #2 (permalink)  
Old April 30th, 2009, 08:43 PM
Authorized User
Points: 81, Level: 1
Points: 81, Level: 1 Points: 81, Level: 1 Points: 81, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Default

I removed this part of the code in the master page code-behind, and everything worked, except the Warnings for the CSS Classes I mentioned:

'If lstPreferredTheme.Items.FindByValue(selectedTheme) IsNot Nothing Then
' lstPreferredTheme.Items.FindByValue(selectedTheme) .Selected = True
'End If

But the listbox no longer pre-selects the option. What's causing this null reference? Thanks

Last edited by janilane; April 30th, 2009 at 11:00 PM.
Reply With Quote
  #3 (permalink)  
Old May 1st, 2009, 06:27 AM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,052
Thanks: 80
Thanked 1,581 Times in 1,558 Posts
Default

Hi there,

When you debug, how does the DropDownList look? Does it contain any items?

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!
Reply With Quote
  #4 (permalink)  
Old May 1st, 2009, 06:28 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

Hi,

Have you tried using the source code that can be downloaded? Does that work?

Usually when you get the warning class or CssClass is not defined means that in the relevant CSS file you have not declared the style rule.

CSS is a case sensitive language so ensure that everything is exactly as it should be.

Check that the link is correct to the css file.

You might want to check that you haven't accidentally deleted a closing comment tag "*/" this would mean that the browser wont read your style declarations.

I don't know what is really causing your second error. Remember you have to declare something before it can be referenced.

So you could be placing the code in the wrong event handler and check that you have called your dropdown list lstPreferredTheme and not something else..
Reply With Quote
  #5 (permalink)  
Old May 3rd, 2009, 05:42 PM
Authorized User
Points: 81, Level: 1
Points: 81, Level: 1 Points: 81, Level: 1 Points: 81, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Hi,

Thanks for that. The WARNINGS disappear when I rebooted my machine twice. But when I ran the application again and accessed the sub-menus and GOT the exception, the WARNINGS have appeared again in the editor. Really strange behavior, might be related to the instance exception?

Imar, the dropdown has a value, the selected one depends on the last theme that I've used when i run my app. Thanks

Last edited by janilane; May 3rd, 2009 at 05:52 PM.
Reply With Quote
  #6 (permalink)  
Old May 4th, 2009, 03:34 AM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,052
Thanks: 80
Thanked 1,581 Times in 1,558 Posts
Default

Hi there,

There are a few problems with the project you sent me.

First, and the biggest issue, is that you didn't create a "Web Site Project", but a "Web Application Project". That is, when you started the project, you choose File | New Project rather than File | New Web Site. You'll run into more problems with this later when Profile is discussed. If you want, you can use one of the existing code examples from the download and start at the end of Chapter 6 with the code I supplied.

Secondly, you have the DropDownList in the Master wrapped in another ContentPlaceHolder. For your /Default.aspx page where you don't have an associated Content control, this is not a problem. It is a problem, however, in other pages, like Reviews\Default.aspx page where you added a Content control referring to this ContentPlaceHolderTest. If you remove the placeholder from the master page and the content control from the other pages, they should work as well.

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!
Reply With Quote
  #7 (permalink)  
Old May 4th, 2009, 06:27 PM
Authorized User
Points: 81, Level: 1
Points: 81, Level: 1 Points: 81, Level: 1 Points: 81, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Wow! I didn't know there was quite a difference between the two types, can't remember that I've chosen Web Application Project!

Anyway, I'm re-writing all codes, starting from the beginning again instead of copying the finished code, just to refresh my learning.

What's the cause of the WARNINGS? Im getting them most times and some times I don't.

Thanks heaps!

Last edited by janilane; May 4th, 2009 at 08:36 PM.
Reply With Quote
  #8 (permalink)  
Old May 5th, 2009, 03:49 AM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,052
Thanks: 80
Thanked 1,581 Times in 1,558 Posts
Default

Check out page 34 and 35 of the book. It discusses both types and explains that Web Site Projects are used exclusively in this book. The TIO that follows then shows you how to create the site using FIle | New Web Site....

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!
Reply With Quote
Reply


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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 1 - NerdDinner - Errors Steve S BOOK: Professional ASP.NET MVC 1.0 ISBN: 978-0-470-38461-9 17 May 22nd, 2010 03:22 PM
More Errors in chapter 7..... rollercoaster BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 5 October 3rd, 2006 03:49 PM
Chapter 4 Example Code Errors beckerm13 BOOK: Professional Ajax ISBN: 978-0-471-77778-6 3 September 28th, 2006 03:40 PM
Chapter 6 Try It Out errors Voltron ASP.NET 2.0 Basics 0 August 9th, 2006 01:42 AM
Chapter 4 Errors? DRAYKKO BOOK: Beginning Java 2 3 June 1st, 2004 07:47 AM



All times are GMT -4. The time now is 08:22 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.