beginer in ASP - how to implement counter

M

Mario Krsnic

Hello everybody,
This works in vb.net. The value of n increments:

Public Class Form1
Dim n%
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
n = n + 1
Label1.Text = n
End Sub
End Class

The "same" thing does not work in ASP.NET (VWD 2005). The value of n remains
allways 1.

Partial Class _Default
Inherits System.Web.UI.Page
Dim n%
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
n = n + 1
Label1.Text = n
End Sub
End Class

What should I do to make n increase?
Thanks for every advice.
Mario
 
V

V

You can also store n in the cache and increment and store it back to
the cache everytime. But of course, in the cache, it becomes a global
variable.

- Vaibhav
 
J

Juan T. Llibre

Hi, Mario.

Why do I get the feeling that this is a
basic programming class homework assignment ?

:)

In any case, try this :

Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = Val(Label1.Text) + 1
End Sub

Also, please don't refer to ASP.NET as "ASP", per your subject.

ASP is ASP; ASP.NET is ASP.NET.
Let's keep them separate so there's no confusion.
 
J

Juan T. Llibre

If all he wants to do is increment the value, he can simply use :

Label1.Text = Val(Label1.Text) + 1

If he want to use the result for something else,
he can capture it to a variable and process it.
 
J

Juan T. Llibre

re:
But of course, in the cache, it becomes a global variable.

And, of course, too, that won't do.

If all he wants to do is increment the value, he can simply use :

Label1.Text = Val(Label1.Text) + 1

If he want to use the result for something else,
he can capture it to a variable and process it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top