Click here to Skip to main content
13,449,155 members (49,480 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i am developing an online exam application so i used stop watch. But this stop watch is reset when page is reload or press F5 button. I don't want to reset stop watch. So please help me i am so in trouble.
My code is :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs" Inherits="Default7" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
<script type="text/javascript" language="javascript">
var msec = 0;
var sec = 0;
var min = 0;

function starttimer(){
var hdntime = document.getElementById("hdntime");
hdntime.innerHTML = min + ":" + sec + ":" + msec;
go = setTimeout("starttimer()", 1);
if (msec == 100) {
msec = 0;
if (sec == 60) {
sec = 0;
function resetwatch() {
<form id="form1" runat="server">


<input id="Button1" type="button" value="Start Watch" onclick="starttimer()"/>
<input id="Button2" runat="server" type="button" value="Stop Watch" onclick="stopwatch()" />
<input id="Button3" type="button" value="Reset Watch" onclick="resetwatch()" />

Posted 27-Jan-13 23:04pm
E.F. Nijboer 28-Jan-13 5:31am
You cannot track this client side because it isn't tamper proof. You should store the start time of the user in a server session and use that. Your website shows just an indicator of the time left but when submitting the exam, you should check if the user is within the time limit (using the start time stored on the server)
Member 10033955 27-Jun-13 4:29am
I want that for the php.
If you have any solution do mail me at

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

try this it as demo....then try implement in your logic....what u have to do is save time in session variable.....
.aspx page as follow

<asp:Panel ID="Panel1" runat="server" Height="303px">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"

        <br />

      <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />

                            <asp:Button ID="Button3" runat="server" Text="Start" Width="213px"

                    onclick="Button3_Click" />

                            <br />
                            <br />

                <asp:Label ID="Label9" runat="server" Text="Remaining Time"></asp:Label>
                <asp:Label ID="Label8" runat="server" Text=""></asp:Label>
                <br />
        <br />
        <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
                <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
        <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
                <br />
                <hr />
                 <asp:RadioButton ID="RadioButton1" runat="server" GroupName="option1" />
        <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
        <br />
        <br />
        <asp:RadioButton ID="RadioButton2" runat="server" GroupName="option1" />
        <asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
        <br />
        <br />
        <asp:RadioButton ID="RadioButton3" runat="server" GroupName="option1" />
        <asp:Label ID="Label6" runat="server" Text="Label"></asp:Label>
        <br />
        <br />
        <asp:RadioButton ID="RadioButton4" runat="server" GroupName="option1" />
        <asp:Label ID="Label7" runat="server" Text="Label"></asp:Label>
        <br />
        <br />

       <asp:Button ID="Button1" runat="server" Text="Next" Width="215px"

            onclick="Button1_Click" />


.cs file i.e code behind file.....

protected void Button3_Click(object sender, EventArgs e)
        Timer1.Enabled = true;
        Session["start_time"] = DateTime.Now.ToLongTimeString();
        //Session["end_time"] = DateTime.Now.AddMinutes(1).ToLongTimeString();
        Session["end_time"] = 15;
        Button3.Enabled = false;
        Session["question_counter"] = 0;
        Session["rightquestions"] = 0;
        Session["currentans"] = "";
        Button1_Click(null, null);
    protected void Button1_Click(object sender, EventArgs e)

    protected void Timer1_Tick(object sender, EventArgs e)
        Session["end_time"] = (int.Parse(Session["end_time"].ToString()) - 1).ToString();

        if (Session["end_time"].ToString() == "0")

            Timer1.Enabled = false;


        Label8.Text = Session["end_time"].ToString();

remember this is not complete is demo...ur problem of refresh is have solution over here....on Next button click it is not refreshed....try it...and then apply ur logic for Next question...most importantly all online exam give warning message before start exam that "DO NOT REFRESH PAGE DURING EXAMINATION TIME"....hope it will help...
rahemani_1200 29-Jan-13 5:03am
thanx Palavi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03-2016 | 2.8.180318.3 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100