Hi nauna,
Check this sample.
HTML
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="dvTimer">
<asp:Label ID="lblTimer" runat="server" Text="10:00" />
<asp:Timer runat="server" Interval="1000" OnTick="OnTimerTick">
</asp:Timer>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Namespaces
C#
using System.Drawing;
VB.Net
Imports System.Drawing
Code
C#
protected void OnTimerTick(object sender, EventArgs e)
{
int sec = 0;
if (ViewState["Time"] == null)
{
ViewState["Time"] = 10;
}
else
{
sec = Convert.ToInt32(ViewState["Time"]);
sec--;
ViewState["Time"] = sec;
}
if (ViewState["Time"] != null)
{
lblTimer.ForeColor = Color.Black;
lblTimer.Text = ViewState["Time"].ToString().PadLeft(2, '0') + " : 00";
}
if ((int)ViewState["Time"] == 1)
{
lblTimer.ForeColor = Color.Red;
ViewState["Time"] = null;
}
}
VB.Net
Protected Sub OnTimerTick(ByVal sender As Object, ByVal e As EventArgs)
Dim sec As Integer = 0
If ViewState("Time") Is Nothing Then
ViewState("Time") = 10
Else
sec = Convert.ToInt32(ViewState("Time"))
sec -= 1
ViewState("Time") = sec
End If
If ViewState("Time") IsNot Nothing Then
lblTimer.ForeColor = Color.Black
lblTimer.Text = ViewState("Time").ToString().PadLeft(2, "0"c) & " : 00"
End If
If CInt(ViewState("Time")) = 1 Then
lblTimer.ForeColor = Color.Red
ViewState("Time") = Nothing
End If
End Sub
Screenshot