Results 1 to 7 of 7

Thread: +1 integer and make it display?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    +1 integer and make it display?

    I am using the following code,


    vb Code:
    1. Partial Class _Default
    2.     Inherits System.Web.UI.Page
    3.     Public count As Integer = 0
    4.  
    5.     Protected Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    6.         count += 1
    7.  
    8.         Label1.Text = "You clicked the button " & count.ToString & " times!"
    9.     End Sub
    10. End Class

    however, all the page ever displays is "You clicked the button 1 times"

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: +1 integer and make it display?

    Thread moved from the 'ASP, VB Script' forum to the 'ASP.Net' forum

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: +1 integer and make it display?

    ah thank you.

  4. #4
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: +1 integer and make it display?

    timers are designed for windows forms not asp.net web forms but you set the label.text as "You clicked the button..." so I'm confused over what you are trying to do.

    lastly a public page scope variable will not persist over post backs, you need to store the value somewhere like viewstate to do this. Here is a example

    Code:
    sub btn_click(.......) handles button1.click
    
    dim i as integer = 0
    
    if isnothing(viewstate("counter")) then
      'first time
      i = 1
    else
      i = viewstate("counter") + 1
    end if
    
    viewstate("counter") = i
    Label1.Text = "You clicked the button " & i & " times!"
    
    end sub
    The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded.

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: +1 integer and make it display?

    TCarter,

    Are you just starting out with ASP.Net? Have you done Windows Forms Development before?

    You will find that although there are lots of similarities between ASP.Net and Windows, there are a few MAJOR differences, which Brin has touched on above. Once you get your head around these differences, you will find that a lot of stuff starts to make sense.

    Let us know if you have any other questions.

    Gary

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: +1 integer and make it display?

    sorry for the long delay,

    Yes. I am new to ASP.Net, not new to forms.

    I am going to be reading over your tutorials in your sig. Thanks for the insight.

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: +1 integer and make it display?

    Sounds good.

    Let me know if you have any other questions.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width