Hi
As an example..
Have a javascript as below at the header of the page. if you are using master page then in the master page header section
<script type="text/javascript" language="javascript">
function displayRemainingTime() {
var totalTime = parseInt(document.getElementById("totalTime").value);
var elapsedTime = parseInt(document.getElementById("elapsedTime").value);
var remainTime = totalTime - elapsedTime;
document.getElementById("timerDisplay").innerHTML = "Time elapsed: " + elapsedTime + " minutes, " + remainTime + " minutes Remains";
elapsedTime = elapsedTime + 1;
document.getElementById("elapsedTime").value = elapsedTime;
//alert(elapsedTime);
}
</script>
At the body on load event call this function
<body onload="displayRemainingTime();"
The aspx page will have this controls..
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:Label ID="timerDisplay" ClientIDMode="Static" runat="server" Text="Label"></asp:Label>
<input type="text" id="totalTime" clientidmode="Static" runat="server" style="visibility:hidden"/>
<input type="text" id="elapsedTime" clientidmode="Static" runat="server" style="visibility:hidden"/>
<asp:Button ID="Button1" runat="server" Text="Button" />
</asp:Content>
From your code behind of the aspx page at page_load event have this code..
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
totalTime.Value = "30";// The exam total time in minutes.
elapsedTime.Value = "0";
}
ClientScript.RegisterStartupScript(this.GetType(), "script1", "<script type='text/javascript'>setInterval('displayRemainingTime()',60000);</script>;");
}
The workflow is
1) Assign the total time into a hidden text box.
2) javascript read it and calculate the remaining time. Set the elapsed time into a hidden text box
3) Both these textboxes will be having the values as such during post back. So the javascript can use that values
4)At page load we are injecting a interval script which is scheduled to run at one minute.
hope this helps