Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > beginer in ASP - how to implement counter

Reply
Thread Tools

beginer in ASP - how to implement counter

 
 
Mario Krsnic
Guest
Posts: n/a
 
      06-18-2006
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


 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      06-18-2006
The page class is instantiated every time the page loads. That means
that you get a new variable n every time the page loads.

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:

http://msdn.microsoft.com/library/de...Management.asp

Mario Krsnic wrote:
> 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
>
>

 
Reply With Quote
 
 
 
 
V
Guest
Posts: n/a
 
      06-18-2006
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

Mario Krsnic wrote:
> 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


 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      06-18-2006
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.



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$(E-Mail Removed)...
> 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
>




 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      06-18-2006
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/
===================================
"Göran Andersson" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> The page class is instantiated every time the page loads. That means that you get a new variable n
> every time the page loads.
>
> 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:
>
> http://msdn.microsoft.com/library/de...Management.asp
>
> Mario Krsnic wrote:
>> 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



 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      06-18-2006
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.



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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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
>
> Mario Krsnic wrote:
>> 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

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Page File counter and Private Bytes Counter George2 C++ 1 01-31-2008 09:27 AM
Session("counter") vs. ViewState("counter")...a newbie question The Eeediot ASP .Net 3 12-22-2004 09:31 PM
How to implement counter? Tu-Thach ASP .Net 0 07-24-2003 05:22 PM
Re: How to implement counter? Tom Vande Stouwe MCSD.net ASP .Net 0 07-24-2003 05:21 PM



Advertisments