"Paulo" <er********@terra.com.brwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hi, beginner on asp.net 2.0 C# VS 2005, how can I use the shopping cart
concept on my application? When the user clicks add item, it will be
stored on some storage format, I dont know what is the term: temp/global
DataSet, etc... and it should be read on other web-form to checkout the
items...
Basically, you have several choices depending on how you've designed your
web app, and what resources you have at your disposal...
As you've discovered, the information in the shopping cart needs to be
persisted (i.e. "remembered") across multiple pages. Therefore, you can't
use ViewState. However, it's vital that different concurrent users don't get
their shopping carts mixed up, so you can't use the Application object
either.
Does your web app use a back-end database? If so, then you can use that to
store the shopping cart. This will also have the advantage that users could
"save" their cart and come back to it later. Some people like to offer this
facility...
Alternatively, even if your web app does use a database, you might prefer to
persist the cart information in the Session object. This is very simple to
do. Obviously, if you use the Session object, then any information stored in
it will be lost when the Session ends either because the user has logged out
and you've torn down the Session in code, or because it has timed out...
A third alternative would be to store the cart data in a cookie. However,
this would obviously not work if the user has disabled cookies in their
browser - some users do this for (supposed) security reasons.
Personally, I use the Session object for shopping cart. I use a
Dictionary<int, intgeneric for this. The Dictionary is keyed on the
product's unique identifier, and the value is the number of items purchased.
This has the advantage of keeping the object persisted in Session as small
as possible.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net