Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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 14th, 2003, 02:11 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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 !
 
Old July 15th, 2003, 01:30 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

  Anybody is able to assist me out there?
 
Old July 15th, 2003, 02:04 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Hi there:
well when u click a button since the ASPX keep states clicked button has it state in postback. thats why it increase the session value.
but if u click Empty it i'll make the session empty even.
And if u add a new button with no event( just to poastback the page) & click than the refresh nothing happend.
its all i guess, & hope helped u.

Always:),
Hovik Melkomian.
 
Old July 17th, 2003, 02:53 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Help............
 
Old July 17th, 2003, 02:57 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Sorry I an new to aspx but from what I have read you might want to try putting a if (!PostBack){} around your addclick code.
Again I am a novice but your not getting much else in the way of adivse.

Good Luck
Rod




Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.Net without session. soccers_guy10 ASP.NET 1.0 and 1.1 Professional 1 May 8th, 2007 05:49 AM
Problem using Session in ASP.NET Scripts82 VB.NET 2002/2003 Basics 0 December 6th, 2006 09:03 AM
Session Hnadling in Asp.net sana ASP.NET 1.0 and 1.1 Basics 0 March 30th, 2006 01:02 AM
session variables in asp to asp.net marvz ASP.NET 2.0 Basics 0 August 1st, 2005 03:09 AM





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