Default.aspx
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server">2:00:00</asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
Default.aspx.vb
Dim timer, timer_arr() As String
timer = Label1.Text
timer_arr = timer.Split(":")
Dim seconds = Integer.Parse(timer_arr(2))
Dim minutes = Integer.Parse(timer_arr(1))
Dim hours = Integer.Parse(timer_arr(0))
If seconds = 0 And minutes = 0 And hours = 0 Then
Timer1.Enabled = False
Else
seconds = seconds - 1
End If
If (seconds < 0) Then
seconds = 59
minutes = minutes - 1
End If
If minutes < 0 Then
minutes = 59
hours = hours - 1
End If
Label1.Text = hours & ":" & minutes & ":" & seconds
The above code showing the expected result, i mean, i need the count down timer, which will display the countdown timer to the client like 2:45:34. But the problem is the value of seconds is decreasing by twice. i mean after 2:45:34 in the next second instead of displaying 2:45:33, it displaying 2:45:32 and so on. I’m very confused, from my point of view, everything is all right. Need help !!
UPDATED
I believe, client side scripting i.e. javascript will be the another option, but i need the timer for online exam system, which means timer should continue ticking whenever client send the request to the server. But, if i will use javascript then timer value will interrupted and will show unexpected value i.e. may be initialized again, and other cause. So, i believe server side scripting will be the best. If anyone have other suggestion, then i will appreciate. !!
I know, its too late to share answer of this question, Since, i found this solution and i felt, other can get the benefit of my solution.
this is what i done…
I have used hiddenfield, which keep update the timer and now, i’m using
<div>on which i’m displaying the counternow i added my javascript and css code to my file for better look of count-down timer
timer.js
timer.CSS
You can see demo of countdown timer here