function DisplaySessionTimeout() {
var sessionTimeout = $('#ctl00_contentPlaceHolder1_hdnSecondsLeft').val();
//assigning minutes left to session timeout to Label
var hours = Math.floor(sessionTimeout / 3600);
var time = sessionTimeout - hours * 3600;
var min = Math.floor(time / 60);
var sec = time % 60;
if (hours < 10) {
hours = "0" + hours;
}
if (min < 10) {
min = "0" + min;
}
if (sec < 10) {
sec = "0" + sec;
}
$('#ctl00_contentPlaceHolder1_lblSessionTime').text(hours + ":" + min + ":" + sec);
//sessionTimeout;
sessionTimeout = sessionTimeout - 1;
$('#ctl00_contentPlaceHolder1_hdnSecondsLeft').val(sessionTimeout);
//if session is not less than 0
if (sessionTimeout >= 0)
//call the function again after 1 minute delay
window.setTimeout("DisplaySessionTimeout()", 1000);
else if (sessionTimeout == 60) {
//show message box
alert("Your test will end in 1 minute.");
}
else {
//show message box
alert("Your current Session is over.");
}
}
Above is the final code i came up with and it works!!!
Govil
Marked as answer by amitgovil on Nov 16, 2012 09:00 AM
AmitGovil
Member
58 Points
70 Posts
Close session on Online Test
Nov 16, 2012 05:06 AM|LINK
Hi
I have created a template for online test, which has a time duration in minutes. Different test would have different time limit.
And i want to expire the session or end the test or give an alert message when the time ends and also notify few minutes before time ends.
Any suggestion or help?
Thanks
Amit
urenjoy
Star
12367 Points
1862 Posts
Re: Close session on Online Test
Nov 16, 2012 05:29 AM|LINK
You can redirect to another page using javascript and on the page_load:
protected void Page_Load(object sender, EventArgs e) { Session.Abandon(); FormsAuthentication.SignOut(); FormsAuthentication.RedirectToLoginPage(); // Response.Redirect(clsCommon.value("login.aspx?mode=logout"); }check following:
http://www.codeproject.com/Articles/24669/JavaScript-to-Show-Session-Timeout-Counter
AmitGovil
Member
58 Points
70 Posts
Re: Close session on Online Test
Nov 16, 2012 05:51 AM|LINK
Thanks fr the reply!
What if i want to change on every second.
Lets say, time limit is 20 minutes and the counter should goes like :
19:59
19:58
19:57
.
.
.
.
00:02
00:01
Time Over!
AmitGovil
Member
58 Points
70 Posts
Re: Close session on Online Test
Nov 16, 2012 08:59 AM|LINK
Anyways, got help from link below to get the time left:
http://stackoverflow.com/questions/3733227/javascript-seconds-to-minutes-and-seconds
function DisplaySessionTimeout() { var sessionTimeout = $('#ctl00_contentPlaceHolder1_hdnSecondsLeft').val(); //assigning minutes left to session timeout to Label var hours = Math.floor(sessionTimeout / 3600); var time = sessionTimeout - hours * 3600; var min = Math.floor(time / 60); var sec = time % 60; if (hours < 10) { hours = "0" + hours; } if (min < 10) { min = "0" + min; } if (sec < 10) { sec = "0" + sec; } $('#ctl00_contentPlaceHolder1_lblSessionTime').text(hours + ":" + min + ":" + sec); //sessionTimeout; sessionTimeout = sessionTimeout - 1; $('#ctl00_contentPlaceHolder1_hdnSecondsLeft').val(sessionTimeout); //if session is not less than 0 if (sessionTimeout >= 0) //call the function again after 1 minute delay window.setTimeout("DisplaySessionTimeout()", 1000); else if (sessionTimeout == 60) { //show message box alert("Your test will end in 1 minute."); } else { //show message box alert("Your current Session is over."); } }Above is the final code i came up with and it works!!!