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
Web pages are stateless by design. If you want to maintain a value
across pages, you have to use one of the methods for maintaining state:
- Vaibhav
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.
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mario Krsnic" <pdl@remove_sofort-start.de> wrote in message news:e739ef$s5a$1...@online.de...
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.
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"V" <vaibhav...@gmail.com> wrote in message
news:1150629098.2...@r2g2000cwb.googlegroups.com...
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.
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Göran Andersson" <gu...@guffa.com> wrote in message news:uFHM8Osk...@TK2MSFTNGP05.phx.gbl...