I am creating an online exam website and I want to set a 30 minute timer for 30 questions... Can anyone tell me how to use the timer control in asp.net or any other easy method?
-
5What have you tried so far?Darin Dimitrov– Darin Dimitrov2012-06-14 11:27:03 +00:00Commented Jun 14, 2012 at 11:27
-
please tell us WhatYouHaveTried.com and How to Ask (the homework section). Essentially you set a timer control to have a refresh rate in milliseconds and enable its Tick Event. Hence set the timer to 1800000 when the test starts and on the first Tick event end the exam.Jeremy Thompson– Jeremy Thompson2012-06-14 11:48:53 +00:00Commented Jun 14, 2012 at 11:48
-
you should show mattgemmell.com/what-have-you-triedManish Jain– Manish Jain2019-06-16 05:12:43 +00:00Commented Jun 16, 2019 at 5:12
4 Answers
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
</asp:Timer> // For one minute
<asp:UpdatePanel ID="UpdatePanel1"
runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick">
</asp:AsyncPostBackTrigger>
</Triggers>
</asp:UpdatePanel>
protected void Timer1_Tick(object sender, EventArgs e)
{
// Label1.Text = DateTime.Now.Second.ToString();
}
Comments
One possible way would be to:
- create an UpdatePanel where you would insert every question and the possible answers
- in the UpdatePanel you can insert a UserControl that represents a question (for example this UserControl would contain a label with the question and some radio buttons or checkboxes with associated labels for the answers)
- inside the UpdatePanel you could use the Timer control like in this example on Msdn http://msdn.microsoft.com/en-us/library/bb398865.aspx
<asp:Timer id="Timer1" runat="server" Interval="120000" OnTick="Timer1_Tick"> </asp:Timer> - the function defined in the OnTick event of the Timer control will be fired on the server side after each time interval expires; there you would load the UserControl with the values for the next question and check if the test is finished or if the total time has elapsed (for example by summing the total elapsed time in a variable)
You could also display a countdown in the page if needed and use JavaScript to update it.
Comments
...Or you could use JQuery. Set up a timer (http://code.google.com/p/jquery-timer/) and then trigger a times up action at the end. Can make use of Ajax to try answers etc - but this keeps everything else at the front end.
Comments
Adding Timer Control inside Update Panel is a way in which the page flicker or total page refresh can be avoided and user can have a smooth experience. But timer control is inefficient as repeated requests are sent to the server which can cause overload and unnecessary waste of resources. AJAX would be a better alternative or any client side javascript could be better. Polling is another method which is efficient.