Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
The below code is used to create a timer in .aspx.cs file. Please help me as soon as possible. Its an online exam application. I need to crack this timer issue soon. Its been a big hurdle for me from a week. Please help. thanks in Advance.

What I have tried:

htmlTable.Append("<script> var seconds = " + ttime + "; function secondPassed() { var minutes = Math.round((seconds - 30) / 60); var remainingSeconds = seconds % 60; if (remainingSeconds < 10) { remainingSeconds = '0' + remainingSeconds; } document.getElementById('countdown').innerHTML = 'Time Left :- ' + minutes + ':' + remainingSeconds; if (seconds == 0) { clearInterval(countdownTimer);document.getElementById('Button1').click(); } else { seconds--; } } var countdownTimer = setInterval('secondPassed()', 1000);</script>");

PlaceHolder1.Controls.Add(new Literal { Text = htmlTable.ToString() });
Posted
Updated 17-Jun-16 18:42pm
Comments
F-ES Sitecore 19-Jun-16 8:50am    
In your "secondPassed" function store the remaining time in a cookie, and on the page_load of your page see if the cookie exists and if it does make its value the default remainingSeconds value. It won't stop people cheating though, as they can alter the cookie value to give themselves more time, so I'd come up with a server-side back-up too.

1 solution

CodeProject is your friend: [^], and so are search engines.
 
Share this answer
 

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