incrementing integer variable with timer?
incrementing integer variable with timer?
incrementing integer variable with timer?
incrementing integer variable with timer?
incrementing integer variable with timer?
incrementing integer variable with timer? incrementing integer variable with timer? incrementing integer variable with timer? incrementing integer variable with timer? incrementing integer variable with timer? incrementing integer variable with timer? incrementing integer variable with timer? incrementing integer variable with timer?
incrementing integer variable with timer? incrementing integer variable with timer?
incrementing integer variable with timer?
Go Back  Xtreme Visual Basic Talk > > > incrementing integer variable with timer?


Reply
 
Thread Tools Display Modes
  #1  
Old 02-09-2011, 06:05 AM
Meridian2000 Meridian2000 is offline
Contributor
 
Join Date: Jul 2003
Location: London/England
Posts: 573
Default incrementing integer variable with timer?


I know this is so very basic, but I can't seem to get the following code to work 'x' always returns 1 in my aspx page! can anyone please help?

Code:
 Public x As Integer
    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        x = x + 1
        TextBox1.Text = x
    End Sub
__________________
Bumshanka - May the seed of your loins be fruitful in the belly of your woman - The Young Ones
Reply With Quote
  #2  
Old 02-09-2011, 06:27 AM
PlausiblyDamp's Avatar
PlausiblyDampincrementing integer variable with timer? PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

The variable x is tied to an instance of the page, however the page is created and destroyed for every postback request / ajax call - this means each time the timer ticks a new page is created which will have the variables set to their default values.

You will need to look at some form of state management (Session etc) to get values to persist across postbacks.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 02-09-2011, 06:41 AM
Meridian2000 Meridian2000 is offline
Contributor
 
Join Date: Jul 2003
Location: London/England
Posts: 573
Default

That's great many thanks, I've put Session("intger") = 1 in the page load event on my login page and change the other page to
Code:
    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Session("intger") = Session("intger") + 1
        TextBox1.Text = Session("intger")
    End Sub
This works
__________________
Bumshanka - May the seed of your loins be fruitful in the belly of your woman - The Young Ones
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
incrementing integer variable with timer?
incrementing integer variable with timer?
incrementing integer variable with timer? incrementing integer variable with timer?
incrementing integer variable with timer?
incrementing integer variable with timer?
incrementing integer variable with timer? incrementing integer variable with timer? incrementing integer variable with timer? incrementing integer variable with timer? incrementing integer variable with timer? incrementing integer variable with timer? incrementing integer variable with timer?
incrementing integer variable with timer?
incrementing integer variable with timer?
 
incrementing integer variable with timer?
incrementing integer variable with timer?
 
-->