Reputation: 2120
I am using a web application where a person want to book a table. Before payment, the table is reserved for that person for 30 minutes. If he doesn't make any payment his reservation is deleted.
I want to display a count down timer of Minutes and seconds to that person so that he may know how much time left in reservation before payment.
I know how to use timer but how should I use it in my case?
The reservation time is saved in database. I want the timer to start like 30:00 and start decreasing the time. Should I initial value from database ? or just set its value to something like 30:00 ? I don't know what to do. please help
Protected Sub UpdateTimer()
Label1.Text = System.DateTime.Now.ToLongTimeString()
End Sub
Protected Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick
UpdateTimer()
End Sub
Upvotes: 1
Views: 596
Reputation: 471
Hope this Help ..
Dim ts As New TimeSpan(0, 30, 0)
Protected Sub UpdateTimer()
ts = ts.Subtract(TimeSpan.FromSeconds(1))
Label1.Text = ts.Minutes & ":" & ts.Seconds
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If ts.Minutes <= 0 And ts.Seconds <= 0 Then
Timer1.Stop()
'<!-- DO SOMETHING HERE -->
Else
UpdateTimer()
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Interval = 1000
Timer1.Start()
End Sub
I'd never used asp but i think they're just the same
Upvotes: 1
Reputation: 718
Dim timercount As Integer = 30 //Value For 3 Minutes
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
lblTimer.Text = timercount.ToString() + " Second."
If timercount = 0 Then
Timer1.Enabled = False
MessageBox.Show("Your booking has been cancelled", "My Application", _
MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Else
timercount -= 1
End If
End Sub
Upvotes: 0