Rahul Lakshakar

Rahul Lakshakar

  • NA
  • 199
  • 41.9k

Countdown timer in asp.net

Mar 30 2017 1:26 PM
i created a count down timer, but i am not getting how to show hour also it just showing seconds and minutes. Can any one guide me please...
 
My code is:
 
protected void Page_Load(object sender, EventArgs e)
{
if (!SM1.IsInAsyncPostBack)
{
Session["timeout"] = DateTime.Now.AddSeconds(120).ToString();
}
}
protected void timer1_tick(object sender, EventArgs e)
{
if (0 > DateTime.Compare(DateTime.Now, DateTime.Parse(Session["timeout"].ToString())))
{
lblTimer.Text = string.Format("Time Left: 00:{0}:{1}",
((Int32)DateTime.Parse(Session["timeout"].ToString()).Subtract(DateTime.Now).TotalMinutes).ToString(),
((Int32)DateTime.Parse(Session["timeout"].ToString()).Subtract(DateTime.Now).Seconds).ToString());
}
else
{
timer1.Enabled = true;
}
}
 

Answers (2)