Countdown Timer RRS feed

  • Question

  • Can anyone can give  code for ajax timer ? the timer start from 45 minute and if the timer reach 00:00 then it will redirect user to default.aspx. I need to show the minute and second and the timer will refresh every second.
    • Moved by Andreas Johansson Tuesday, July 26, 2011 9:46 AM ASP.NET (From:Visual Basic Language)
    Friday, July 22, 2011 7:04 PM

All replies

  • Get a good tutorial here though here is not for ASP.NET:


    See the code behind, you'll handle code-behind and redirect users to default.aspx when UpdateTimer_Tick event is raised.


    Best regards, Saygılarımla, Onur Güzel

    Yazgeliştir Forumları VB.NET / C# Süper Moderatorü.

    Microsoft Haber Grupları Profilim (VB.NET)

    Friday, July 22, 2011 7:07 PM
  • unless you need time from webservice I wouldn't use Ajax. Java client side script will do the same thing with out having to interact with server

    something like:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
     <script language="javascript" type="text/javascript">
      //Ref to timer
      var TimerToStop;
      //time the timer was started 
      var StartTime;
      //Minutes until navigate to new page
      // 1min for test reset to 45min for your app
      var Expire = 1
      function Page_OnLoad() {
       //Set start time
       StartTime = new Date();
       //Create timer and save referance to it
       TimerToStop = window.setInterval("Tick()", 250);
      function Tick(){
       var CurrentTime = new Date();
       var Elapsed = new Date(CurrentTime - StartTime);
       var divRemaining = document.getElementById("divRemaining");
       if (Elapsed.getMinutes() >= Expire) {
        //Stop Timer
        //go to Google
        divRemaining.innerHTML = "See ya...";
       var tmSec = 60 - Elapsed.getSeconds();
       var tmMin = Expire-Elapsed.getMinutes() - 1;
       var Min = "0" + tmMin;
       var Sec = "0" + tmSec;
       divRemaining.innerHTML = Min.substr(Min.length - 2) + ":" + Sec.substr(Sec.length - 2);
    <body onload="Page_OnLoad();">
     <form id="form1" runat="server">
      <div id="divRemaining"></div>

    Friday, July 22, 2011 8:39 PM