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 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8
This is the forum to discuss the Wrox book Beginning ASP.NET 2.0 by Chris Hart, John Kauffman, David Sussman, Chris Ullman; ISBN: 9780764588501
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 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
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 16th, 2010, 08:46 AM
Authorized User
 
Join Date: Jan 2010
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 13 - Shopping cart class error

Hi everyone,

having an issue with the code for the shopping cart in chapter 13 as follows:

[Serializable]

public class shoppingCart
{
private DateTime _dateCreated;
private DateTime _lastUpdate;
private List<CartItem> _items;

public ShoppingCart()
{
if (this._items == null)
{
this._items = new List<CartItem>();
this._dateCreated = DateTime.Now;
}
}

public List<CartItem> Items
{
get
{
return _items;
}
set
{
_items = value;
}
}


The bold code above produces an error as follows:

Class, struct, or interface method must have a return type.

The code for the rest of the class is completed exactly as per the book, I have even tried copy/pasting the code from the final code sample of the downloaded code and still get the error.

There is a second error when trying to run the application which is located on the ShoppingCartPage.aspx page, line 14 error:

Element 'ShoppingCart' is not a known element. This can occur if there is a compilation error in the web site.

When I try to debug or run the app it goes straight to the first error above which is located in the shopping.cs file.

Any hints?

Thanks,

Chris
  #2 (permalink)  
Old April 16th, 2010, 09:26 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,955
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

Hi there,

Take a look at the capitalization:

public class shoppingCart
...

public ShoppingCart()

The class name is with a lower s, and the constuctor with a capital. As such, the constructor is not recognized as a constructor and thus you get the error you mentioned.

Using a capital S for the class name should fix both errors.

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!
  #3 (permalink)  
Old April 16th, 2010, 01:36 PM
Authorized User
 
Join Date: Jan 2010
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

thanks for that, it helped resolve the initial problem but has now generated other code problems. In the code I had quoted it is now generating an error at the following line:

private List<CartItem> _items;

error: The type or namespace name 'CartItem' could not be found (are you missing a using directive or an assembly reference?)

The code that is defining the namespace is as follows, and it is located on the same page as the line that is generating the error.

namespace Wrox.Commerce
{
[Serializable]

public class CartItem
{
private int _productID;
private string _productName;
private string _productImageUrl;
private int _quantity;
private double _price;
private double _lineTotal;

public void New()
{
}

After this the code is the same as the book where it defines the ProductID function, productName function, etc...

1 - Obviously I am not sure why it is generating this error, I have checked spelling, upper and lower case similarities and so on and still cant see why it has an issue with this. It also generates a second instance of the exact same error but on another line further in the code where the List<CartItem> is being used.

2 - The original message from the first thread is also coming up again but only during the debug/app generation process, the line that the error is being generated from is located in a tem .cs file that asp is generating at run time. The error doesnt occur anywhere else in the code, only in the temp that is created when i try to run the app. How is this happening if the temp page is being created dynamically at runtime?

Thanks again.

Chris
  #4 (permalink)  
Old April 16th, 2010, 01:39 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,955
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

Maybe it's in a different namespace and you need a using statement?

using Wrox.Commerce;

Did you look at the code that comes with the book to see if you can find any differneces?

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!
  #5 (permalink)  
Old April 16th, 2010, 11:59 PM
Authorized User
 
Join Date: Jan 2010
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

my mistake, there are two classes being defined in the page and I had accidently closed the namespace curly brackets after the first class declaration instead of closing it after the second class declaration.

All working now, thanks again for your help.

Chris
 


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 13 Shopping Cart michaelcode BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 9 January 25th, 2010 03:50 AM
Chapter 13: shopping cart problem mysecondlove BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 April 9th, 2008 07:48 PM
Modifying Shopping Cart Class micptpuser BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 October 28th, 2007 01:30 PM
Chapter 13 Shopping Cart disappears after login bwinklesky BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 June 14th, 2007 01:34 PM
Ch.13 Builing a Shopping Cart seannie BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 3 February 7th, 2007 10:11 AM



All times are GMT -4. The time now is 11:47 PM.


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