Answered by:
Countdown Timer For Online Exam

Question
-
User1223035165 posted
Hello,
I am designing Online Examination System. For this I need a count down timer which does not start from beginning. Suppose timer has started from 40 minutes if the user refreshed the page at when the timer showing at 20 minutes then timer will be continue from 20 minutes. And there is also another case if the user is giving the exam and due to any problem if the user not able to continue the exam, if the user again starts the exam then the exam start from where he have left the exam and timer also starts from the remaining time left where he had left the exam.
Can any one suggest how can I achieve the goal.
Thanks,
Deepak PandeyMonday, January 9, 2012 6:29 AM
Answers
-
User-448512826 posted
Hi,
Add to the aspx file between the <form> tags: <span id="timerDisplaySpan"></span> <input type="hidden" id="timeAllocated" name="timeAllocated" value="30" runat="server"> That adds this to the CodeBehind file: protected System.Web.UI.HtmlControls.HtmlInputHidden timeAllocated; You can then set the timeAlloted control in Page_Load: if ( !IsPostBack ) timeAllocated.Value = value-from-database.ToString(); Then add this JavaScript: <script language="JavaScript"> <!-- function window::onload() { var timeAlloted = 30; if ( document.getElementById('timeAllocated').value.length > 0 ) timeAlloted = parseFloat(document.getElementById('timeAllocated').value); else document.getElementById('timeAllocated').value = timeAlloted; document.getElementById('timerDisplaySpan').innerHTML = '<b>Time Remaining: ' + timeAlloted + " Minutes.</b>"; // 1000 = 1 second... window.setInterval('decrementTimer()', 60000); } function decrementTimer() { var timeAlloted = parseFloat(document.getElementById('timeAllocated').value); timeAlloted--; document.getElementById('timeAllocated').value = timeAlloted; document.getElementById('timerDisplaySpan').innerHTML = '<b>Time Remaining: ' + timeAlloted + " Minutes.</b>"; } // --> </script>
refer...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, January 9, 2012 7:27 AM
All replies
-
User522486851 posted
there are two timers available with .asp for this
http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx
implement true threading
http://msdn.microsoft.com/en-us/library/system.web.ui.timer.aspx
and timer control
Monday, January 9, 2012 7:12 AM -
User-525015206 posted
I think making a User specific Session variable for the counter may do your job.
Also, if the user selects to continue after some time, then he/she can save its current status, and at that time, save the status in Database.
Next, when he continues, update the Session Counter variable based on the status saved in Database.
For more information, please refer to the following link:
http://www.dotnetspider.com/resources/42860-Create-Online-Exam-Project-with-ASP-Net-C-Net.aspx
Hope this helps!
Regards,
Varun Shringarpure
Monday, January 9, 2012 7:17 AM -
User-448512826 posted
Hi,
Add to the aspx file between the <form> tags: <span id="timerDisplaySpan"></span> <input type="hidden" id="timeAllocated" name="timeAllocated" value="30" runat="server"> That adds this to the CodeBehind file: protected System.Web.UI.HtmlControls.HtmlInputHidden timeAllocated; You can then set the timeAlloted control in Page_Load: if ( !IsPostBack ) timeAllocated.Value = value-from-database.ToString(); Then add this JavaScript: <script language="JavaScript"> <!-- function window::onload() { var timeAlloted = 30; if ( document.getElementById('timeAllocated').value.length > 0 ) timeAlloted = parseFloat(document.getElementById('timeAllocated').value); else document.getElementById('timeAllocated').value = timeAlloted; document.getElementById('timerDisplaySpan').innerHTML = '<b>Time Remaining: ' + timeAlloted + " Minutes.</b>"; // 1000 = 1 second... window.setInterval('decrementTimer()', 60000); } function decrementTimer() { var timeAlloted = parseFloat(document.getElementById('timeAllocated').value); timeAlloted--; document.getElementById('timeAllocated').value = timeAlloted; document.getElementById('timerDisplaySpan').innerHTML = '<b>Time Remaining: ' + timeAlloted + " Minutes.</b>"; } // --> </script>
refer...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, January 9, 2012 7:27 AM