Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
1.40/5 (3 votes)
See more:
how to use timer control and set timer 300 seconds ...
when it reach it automatically redirect to another page...
help me to do this....
Posted
Updated 26-Feb-18 20:43pm

Hi,

you can do it in javascript.Here 'm providing code for try that

ASP.NET
<head runat="server">
    <title></title>
    <script language ="javascript">
        var sdf;
        function f1() {
            sdf = setTimeout("f2()", 300);
        }
        function f2() {
            location.href = "default2.aspx";
        }
    </script>
</head>
<body onload="f1()">
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>


In the above code you've to set what is your time requirement.
The time here is in millisec so you can give correct time for it.

Here im giving for count down time for you requirement.

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language ="javascript" >
        var tim = 10000;
        var timset;
        function f1() {
            timset = setInterval("f2()", 1000);
        }
        function f2() {

            tim = parseInt(tim) - 10;
            if (parseInt(tim) < 0) {
                clearInterval(timset);
            }
            else {
                document.getElementById("timershow").value = tim;
                timset = setInterval("f2()", 1000);
            }

        }
    </script>
</head>
<body onload ="f1()" >
    <form id="form1" runat="server">
    <div>
      <input type ="text" id="timershow" />
    </div>
    </form>
</body>
</html>

All the best
 
Share this answer
 
v3
Comments
Raghupathiraja 19-Sep-11 10:40am    
thank u...
do u know tamil?
Raghupathiraja 19-Sep-11 10:45am    
how to show the counting timer in the screen in decrease order
could u say?
Muralikrishna8811 19-Sep-11 11:17am    
Sry i don't know tamil

here I used settimeout() method to invoke when that givetime expires

You can use setinterval() method for invoking set intervals to show time
You try this for decrease order..You have to edit this code for you requirement...

XML
<html>
<body>
<div id="countdown"></div>
<div id="notifier"></div>

<script type="text/javascript">

(function () {
  function display( notifier, str ) {
    document.getElementById(notifier).innerHTML = str;
  }

  function toMinuteAndSecond( x ) {
    return Math.floor(x/60) + ":" + (x=x%60 < 10 ? 0 : x);
  }

  function setTimer( remain, actions ) {
    var action;
    (function countdown() {
       display("countdown", toMinuteAndSecond(remain));
       if (action = actions[remain]) {
         action();
       }
       if (remain > 0) {
         remain -= 1;
         setTimeout(arguments.callee, 1000);
       }
    })(); // End countdown
  }

  setTimer(20, {
    10: function () { display("notifier", "Just 10 seconds to go"); },
     5: function () { display("notifier", "5 seconds left");        },
     0: function () { display("notifier", "Time is up baby");       }
  });
})();

</script>
</body>
</html>


Happy coding....
 
Share this answer
 
v2
Comments
Raghupathiraja 20-Sep-11 1:02am    
thank u!!!!!!!!!!!!!!!!!!!!
rkthiyagarajan 20-Sep-11 1:07am    
R u Tamil?
Raghupathiraja 20-Sep-11 1:14am    
ama ...
neenga?
rkthiyagarajan 20-Sep-11 1:47am    
S ....
Raghupathiraja 20-Sep-11 3:08am    
ennaku online examination project pannanum... help pannunga...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900