• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

simple statebag example

This is just a sample, a button increments a counter, which should then be displed using a label. Problem is, the label shows nothing after the button is clicked and posted.

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="SHITBAG.aspx.vb" Inherits="WebApplication4.SHITBAG"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <SCRIPT runat=server>
  sub Page_Load(ByVal Sender as Object, byval e as EventArgs)
 
  lblCounter.Text = Counter.ToString()
  Counter += 1
  end sub
 
  public property Counter() as integer
      get
            if not(ViewState("intCounter") is Nothing) then
            return CInt(ViewState("intCounter"))
            else
            return 0
            end if
      end get
      
      set
            ViewState("intCounter") = value
      end set
   end property
 
  </SCRIPT>
 
  <head>
    <title>SHITBAG</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
  </head>
  <body MS_POSITIONING="GridLayout">

    Counter:
    <form runat=server>
    <asp:Label id="lblCounter" runat="server" />
   
   
    <asp:Button id="Btn" text="Increment Counter" runat="server" />
   
    </form>
  </body>
</html>
0
dprasad
Asked:
dprasad
1 Solution
 
raterusCommented:
you've got some references to codebehind files, something in there could easily be overwriting what you are doing in the script block.  You should implement one or the other, not both.  I edited your exact example to remove these references, and it works.

<%@ Page Language="vb"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <SCRIPT runat=server>
  sub Page_Load(ByVal Sender as Object, byval e as EventArgs)
 
  lblCounter.Text = Counter.ToString()
  Counter += 1
  end sub
 
  public property Counter() as integer
     get
          if not(ViewState("intCounter") is Nothing) then
          return CInt(ViewState("intCounter"))
          else
          return 0
          end if
     end get
     
     set
          ViewState("intCounter") = value
     end set
   end property
 
  </SCRIPT>
 
  <head>
    <title>SHITBAG</title>
  </head>
  <body>

    Counter:
    <form runat=server>
    <asp:Label id="lblCounter" runat="server" />
   
   
    <asp:Button id="Btn" text="Increment Counter" runat="server" />
   
    </form>
  </body>
</html>
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now