ASP .NET using C# session problem !!
Hi,
I got the following code:
<%@ Page language="c#"%>
<script Language="c#" runat="server">
void EmptyClick(object sender, EventArgs e)
{
Session["BasketCount"] = 0;
}
void AddClick(object sender, EventArgs e)
{
if (Session["BasketCount"] != null)
{
int i = (int)Session["BasketCount"];
i++;
Session["BasketCount"] = (object)i;
} else {
Session["BasketCount"] = 1;
}
}
</script>
<html>
<body>
<form id="BasketForm" method="post" runat="server">
<asp:Button id="Empty" OnClick="EmptyClick" runat="server" Text="Empty"/>
<br />
<asp:Button id="Add" OnClick="AddClick" runat="server" Text="Add"/>
<br />
Basket items : <%=Session["BasketCount"]%>
<br />
</form>
</body>
</html>
which I got it from Wrox Beginning ASP .NET using C#.
The book mension that if I refresh this page, the count of the no. of items in the basket will remain the same. But it won't ! When I refresh the page, the no. keep increasing ! How come? Pls help, thanks !
|