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