 |
| ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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
|
|
|
|

July 27th, 2005, 05:20 AM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The Session doesn't work?
Hi,friends,I'm a beginner.
I use the session to store a variable,then I change it,but it doesn't alter ,it seems that the variable isn't stored in the session.
the code as follow
<%@ 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>
When I push the "add" button,the Basket item(Session["BasketCount"]) doesn't increase as expected.
THANKS!
|
|

July 28th, 2005, 04:12 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The code you posted worked fine at my computer as it is, perhaps it is a cookie problem or such.
BTW... I made the code a bit less verbose, and probably a bit less readable... ;)
Code:
void AddClick(object sender, EventArgs e)
{
Session["BasketCount"] =
((Session["BasketCount"] != null)?
(int)Session["BasketCount"] : 0) + 1;
}
Hope it helps, Jacob.
|
|

July 28th, 2005, 06:41 AM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your help,Jacob.
It's so odd that the Session["basketcount"] dosen't changed in my computer,even the cookie has open completely.Maybe something in my iis goes wrong .
|
|

July 28th, 2005, 09:38 AM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have find the sticking point.It was brought about by Zone Labs security software.When I closed it,the problem went all right.
Thank you all the same,jacob.
I find the sticking point all by chance.Hope this topic can help some unlucky beginners like me.(It has puzzled me for nearly one weak!)
|
|

July 28th, 2005, 10:29 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well, don't you think that it was a cookie problem after all then? I have used Zone Alarm as well, and have had similar problems.
Jacob.
|
|

July 28th, 2005, 08:45 PM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Maybe.But when I opened Zone Alarm,I can used the cookie in my programme freely.I setted Zone Alarm by default.
For tomorrow I work hard!
|
|
 |