Wrox Programmer Forums
|
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
 
Old July 27th, 2005, 05:20 AM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to wangweiming
Default 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!
 
Old July 28th, 2005, 04:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old July 28th, 2005, 06:41 AM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to wangweiming
Default

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 .

 
Old July 28th, 2005, 09:38 AM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to wangweiming
Default

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!)


 
Old July 28th, 2005, 10:29 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old July 28th, 2005, 08:45 PM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to wangweiming
Default

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 1 Ctrl+F5 don't work, F5 does work? jimboak BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 June 29th, 2008 03:46 AM
session in imapepath in gridcolumn..Does not work. savan_thakkar ASP.NET 1.0 and 1.1 Professional 0 August 29th, 2006 07:48 AM
Able to Get it work !! rsrika C# 2005 0 March 8th, 2006 09:16 AM
IT DOES WORK vb certified Pro VB.NET 2002/2003 6 August 15th, 2005 08:04 PM
session and cookie problem (empty session file) msincan BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 February 27th, 2005 05:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.