Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.1
This is the forum to discuss the Wrox book Beginning ASP.NET 1.1 with Visual C#.NET 2003 by Chris Ullman, John Kauffman, Chris Hart, Dave Sussman, Daniel Maharry; ISBN: 9780764557088
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.1 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 March 18th, 2004, 03:42 PM
Authorized User
 
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ch 11 Shopping Cart Using Sessions

Please bear with me if i ask stupid questions im a beginner:D i completed the shopping cart using sessions in chapter 11. im slightly confused by it!!
1.in order to add something to the shopping cart you have to click on the Buy it button twice??
2.Then when u want to add another item to the shopping cart you again have to click on it twice and then it adds one item on to the existing item you bought and then adds 1 item onto the new item!! Its Mad!! E.g u click twice on the buy a shirt button - it registers that u have one shirt in the cart, then u click twice on the buy the hat button and it registers that u have 3 shirts and one hat in the cart. ITS VER VERY STRANGE!!
i have downloaded the code off the website and it works the same:( i just want to able to click on the Buy button and that item to be added once to the cart. Ive messed around with the code for hours and hours and hours and guess what NO JOY!! Any help would be greatly appreciated :)
p.s ive posted the code below

 Sub Page_Prerender(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'this method is run before the page is displayed
        'and after all the other events have been processed

        'contents are displaye don the page by binding
        'by contents of the hashtable to the repeater

        Dim basketTable As System.Collections.Hashtable = Session("Basket")
        basketlist.DataSource = basketTable
        basketlist.DataBind()

        'If basketTable.Count = 0 Then
        'lblBasketMessage.Text = "nothing - please buy something!"
        'Else
        ' lblBasketMessage.Text = ""

        'End If

    End Sub
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'each time the page is loaded the session object is checks to see if it contains a basket. If it
        'doesnt an empty basket is created
        If Session("Basket") Is Nothing Then
            InitializeBasket()

        End If
    End Sub



    Sub btnEmptyBasket_Click(ByVal sender As Object, ByVal e As EventArgs)
        'clears out any existing basket data

        InitializeBasket()

    End Sub

    Sub AddItemToBasket(ByVal sender As Object, ByVal e As EventArgs)
        'all 3 item buttons call this method
        'each time this is run it gets the command argument of each property of the revelant button
        'the command arguement then populates the session object

        Dim itemName As String = sender.CommandArgument

        'a hashtable object tempoparily stores the contents of the sessions basket items.
        Dim basketTable As System.Collections.Hashtable = Session("Basket")

        'if the item has never been added to the session before add a new empty entry into the
        'hash table for this entry
        ' If basketTable(itemName) Is Nothing Then
        'basketTable(itemName) = 0
        'End If


        Dim itemCount As Integer = basketTable(itemName)
        basketTable(itemName) = itemCount + 1

    End Sub

    Sub InitializeBasket()
        'clear out the sesson objects and fill it with a new
        'empty has table
        Dim basketTable As New System.Collections.Hashtable
        Session("Basket") = basketTable

    End Sub



End Class


 
Old August 11th, 2004, 11:28 AM
Registered User
 
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to thorin Send a message via MSN to thorin Send a message via Yahoo to thorin
Default

I had the same problem with the C# example. I am using VS.Net with code behind. I had to go into the Web Form Designer generated code section and modify InitializeComponent with this line:
Code:
this.PreRender += new System.EventHandler(this.Page_Prerender);
Hope this helps.

--Thorin Hanson

 
Old November 2nd, 2004, 11:53 AM
Registered User
 
Join Date: Nov 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Replace this line:
Sub Page_Prerender(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
with
Sub Page_Prerender(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Prerender

Note the Handles is equivalent to invoking a delegate in VB.Net



 
Old November 23rd, 2004, 06:08 PM
Registered User
 
Join Date: Nov 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to MSByrnes
Default

Quote:
quote:Originally posted by thorin
 <snip>
Code:
this.PreRender += new System.EventHandler(this.Page_Prerender);
Hope this helps.

--Thorin Hanson

This worked very well, thank you Thorin. Just remember to put in the parameters in your method, i.e. void Page_PreRender(object sender, System.EventArgs e), instead of the way the book has it void Page_PreRender().

--Mark S. Byrnes







Similar Threads
Thread Thread Starter Forum Replies Last Post
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
shopping cart keyvanjan Classic ASP Basics 1 January 9th, 2007 10:16 PM
Shopping Cart seannie ASP.NET 2.0 Basics 0 December 12th, 2006 10:28 AM
Ch 10: Problem with shopping cart example code Storm BOOK: Beginning ASP.NET 1.0 0 October 11th, 2004 03:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.