The following code is javascript containing a timer and other 2 functions
`
var sec;
var min;
var counter=setInterval(timer, 1000); //1000 will run it every 1 second
//set the timer to the session variable only for the first time
if(isPostBack == 'false'){
sec=second;
min=minute;
}
//set the timer
function timer()
{
if(isPostBack == 'true')
{
sec = second;
min = minute;
}
sec=sec-1;
if(sec < 0)
{
sec=59;
min--;
}
else
{
min=min;
}
if(sec <=9 )
{
sec = "0"+sec;
}
document.getElementById("lblCountDown").innerHTML= "Time Left: "+(min<=9 ? "0" + min : min)+" mins"+" "+sec + " secs";
//copy the value of min and sec in fields
document.getElementById("min").value=min;
document.getElementById("sec").value=sec;
//copy the value of min and sec in session variable
minute = min;
second = sec;
if (min <=0 && sec <= 0)
{
clearInterval(counter);
alert("Times Up!!!. Your Test Will Be Auto Submited");
document.getElementById("Submit").click();
return;
}
}
function showKeyCode(e)
{
var keycode =(window.event) ? event.keyCode : e.keyCode;
if(keycode == 116)
{
alert("Page Cannot be refresh");
event.keyCode = 0;
event.returnValue = false;
return false;
}
}
function disableBackButton()
{
window.history.forward(1);
}
` Code in aspx.cs file
`<body onload = "disableBackButton()" onkeydown = "showKeyCode()">
back button is not getting disable can anyone plz suggest the solution?