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

April 30th, 2009, 08:17 PM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 30th, 2009, 08:43 PM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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..
|
|

May 1st, 2009, 06:27 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
When you debug, how does the DropDownList look? Does it contain any items?
Imar
|
|

May 1st, 2009, 06:28 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
|
|
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..
|
|

May 3rd, 2009, 05:42 PM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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..
|
|

May 4th, 2009, 03:34 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

May 4th, 2009, 06:27 PM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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..
|
|

May 5th, 2009, 03:49 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
 |