3

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?

3
  • 5
    What have you tried so far? Commented 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. Commented Jun 14, 2012 at 11:48
  • you should show mattgemmell.com/what-have-you-tried Commented Jun 16, 2019 at 5:12

4 Answers 4

7
<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();
}
Sign up to request clarification or add additional context in comments.

Comments

3

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

0

...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

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.