Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey every1 i need a code by which i can add a timer for an examination ...
my project in an online exam so the user wil specify time for exam and as the timer ends user exam window will get closed.

help plz
Posted
Comments
bhargavpp 10-Nov-12 0:40am    
you have to use Timer class for that and onbutton click start timer after that reduced time by 1 second periodically once it goes to 0 then close that question set timout page that show timeup!!!

1 solution

ajax timer control do the exactly same as you required

Code
<asp:scriptmanager id="ScriptManager1" runat="server" xmlns:asp="#unknown" />
        <asp:timer runat="server" id="UpdateTimer" interval="5000" ontick="UpdateTimer_Tick" xmlns:asp="#unknown" />
        <asp:updatepanel runat="server" id="TimedPanel" updatemode="Conditional" xmlns:asp="#unknown">
            <triggers>
                <asp:asyncpostbacktrigger controlid="UpdateTimer" eventname="Tick" />
            </triggers>
            <contenttemplate>
                <asp:label runat="server" id="DateStampLabel" />
            </contenttemplate>
        </asp:updatepanel>


C#
protected void UpdateTimer_Tick(object sender, EventArgs e)
{
    Response.Write("<script>alert('Time Over')</script>");
    Response.Redirect("result.aspx");
}


interval="5000" mean 5sec, you just need to modify this value 30min.
30min= 60000*30
 
Share this answer
 
v2
Comments
Gunjan Bhasin 16-Feb-13 7:05am    
Hey Shanalal Kasim thanks for your code. It is working fine, but what I am looking for is when test starts I want to show the timer eg: exam time 30mins so I want timer to display 30:00 mins and it should reduce by ever second. How to do that? Please reply if you can help.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900