Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Retaining a value
Message
From
22/10/2009 17:10:42
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Retaining a value
Miscellaneous
Thread ID:
01430818
Message ID:
01430818
Views:
84
I put a label and a button on a form. Every time I click the button, I want the value of the label to increment by one.
I've gone through several attempts to accomplish this, but they all lead to setting the label to the same value everytime the button is pressed. The latest attempt was
Partial Class Default2
    Inherits System.Web.UI.Page
 
    Function increment_counter() As Integer
        Static iCounter As Integer = 0
        iCounter = iCounter + 1
        Return iCounter
    End Function

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = increment_counter()
    End Sub
End Class
I'm sure there's something fundemental I'm missing about the difference between Web and desktop computing....almost certainly something to do with stateless computing......but if somebody could post some sample code, I can use that as a jumping off point.

In case it's relevant, here's the ASPX portion of the code
< %@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

< html xmlns="http://www.w3.org/1999/xhtml">
< head runat="server">
    < title>< /title>
< /head>
< body>
    < form id="form1" runat="server">
    < div>
    
    < /div>
    < asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            
    < asp:Button ID="Button1" runat="server" Text="Button" />
    < /form>
< /body>
< /html>
Thanks to all.........Rich
Next
Reply
Map
View

Click here to load this message in the networking platform