Hi All,
I want to use countdown timer for quiztest. I am using following code:
Timer.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<div id="timelabel"></div>
<script type="text/javascript">
var leave =<%=seconds %>;
CounterTimer();
var interv=setInterval(CounterTimer,1000);
function CounterTimer()
{
var day = Math.floor(leave / ( 60 * 60 * 24))
var hour = Math.floor(leave / 3600) - (day * 24)
var minute = Math.floor(leave / 60) - (day * 24 *60) - (hour * 60)
var second = Math.floor(leave) - (day * 24 *60*60) - (hour * 60 * 60) - (minute*60)
hour=hour<10 ? "0" + hour : hour;
minute=minute<10 ? "0" + minute : minute;
second=second<10 ? "0" + second : second;
var remain=hour + ":"+minute+":"+second;
leave=leave-1;
document.getElementById("timelabel").innerHTML=remain;
if(remain=='00:00:00')
{
window.location = 'Result.aspx'
}
}
</script >
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>
Timer.aspx.cs
public double seconds;
protected void Page_Load(object sender, EventArgs e)
{
seconds = 3600;
}
------
Its working fine but when i click on button its strat again. So please tell me a solution while when button is clicked yet it should work continusoly not start again or not stopped.
please help me.
Thanks in advance
Pankaj