Hello,
I was running the "session.aspx" example from "Beginning ASP.NET using
VB.NET", Ch 10, and came across some strange/unexpected behavior. If the basket has a non-zero item count and the page is then reloaded, the item count gets automatically incremented. It seems as if the AddClick handler is being fired on reload. It does not do this if the item count is zero. Can anyone tell me why is this happening and how I can stop it from doing this? The something similar happens with Exercise 4 (another shopping cart page). Any help would be appreciated, as I'm really stumped on this.
Thanks in advance,
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>