0

I'm trying to use a Timer in my web application, but cant seem to make it work. Here is my code:

VB Code:

Public Class WebForm1 
    Inherits System.Web.UI.Page 

    Protected WithEvents Label1 As System.Web.UI.WebControls.Label 

    Private t As New System.Timers.Timer(2000) 

    Private Sub Page_Load(ByVal sender As Object, _ 
            ByVal e As System.EventArgs) Handles MyBase.Load 
        AddHandler t.Elapsed, AddressOf TimerFired 
        t.Enabled = True 

    End Sub 

    Public Sub TimerFired(ByVal sender As Object, _ 
        ByVal e As System.Timers.ElapsedEventArgs) 
            Label1.Text = Now 
    End Sub 
End Class  

Here I'm trying to change the text of the label every 2 seconds.

4
  • 2
    Do you know the difference between server-side and client-side code? Once the page has been rendered and sent, the client won't know anything of further server-side processing. Also please make your code more readable. Commented Dec 23, 2011 at 18:39
  • In the future when posting questions, please refrain from including tags in the question title and use the code formatting built into the editor. Commented Dec 23, 2011 at 18:39
  • Why do you need to save it every 2 seconds? Commented Dec 23, 2011 at 18:40
  • i trying to learn how can i use the timer in my code in vb.net Commented Dec 23, 2011 at 18:45

1 Answer 1

1

I think you need to learn and study the fundamental difference between server and client code.

By the provided code I think you need to update a label every 2 seconds withe the current date-time. For partial rendering and update of a page (and much more!) there is AJAX, and related timer. Please take a look to this good example about, I think, your needs:

http://www.aspxcode.net/free-asp-net-ajax-source-code.aspx?Topics=How%20to%20Use%20AJAX%20Timer

Sign up to request clarification or add additional context in comments.

1 Comment

If the question is solved please mark the answer. If you need more example please tell me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.