Subject: Ch 10: Problem with shopping cart example code
Posted By: Storm Post Date: 10/11/2004 3:24:22 PM
Hello everyone,
I was running the session.aspx example in ch 10, and came across some strange/unexpected behavior. If the basket has a non-zero count of items and the page is then reloaded, the item count gets automatically incremented. It seems as if the AddClick handler is being fired on reload. Can anyone tell me why is this happening and how I can stop it from doing this? The same thing happens with Exercise 4 (another shopping cart page). Any help would be appreciated.

Thanks and Regards,
Storm

Relevent Code:

<%@ Page language="VB"%>
<SCRIPT language="vb" runat="server">

Sub EmptyClick(Sender as System.Object, E As System.EventArgs)
    Session("BasketCount") = 0
End Sub


Sub AddClick(Sender as System.Object, E As System.EventArgs)
        Session("BasketCount") += 1
End Sub

</SCRIPT>

<HTML>
<HEAD>
    <LINK href="../General.css" rel="stylesheet">
    <TITLE>Session Example</TITLE>
</HEAD>
<BODY>
<FORM id="BasketForm" method="post" runat="server">
    <ASP:button id="btnEmpty" text="Empty" onClick="EmptyClick" runat="server" />
    <BR/>
    <ASP:button id="btnAdd" text="Add" onClick="AddClick" runat="server" />
    <BR/>
    Basket Items: <%=Session("BasketCount") %>
    <BR/>
</FORM>
</BODY>
</HTML>



Go to topic 20348

Return to index page 747
Return to index page 746
Return to index page 745
Return to index page 744
Return to index page 743
Return to index page 742
Return to index page 741
Return to index page 740
Return to index page 739
Return to index page 738