Solved

I need to use a timer in my web app, are there any timer controls available or is there an easy way round this problem?

Posted on 2004-09-29
10
166 Views
Last Modified: 2010-04-23
I need to time an exam.

At the start of the exam I must give the candidates 10 minutes to answer 10 questions.

The timer must be visible to the user.

If the timer ticks down to zero, I must be able to program something to happen by this event.

Your help would be much appreciated.

Regards

PG
0
Comment
Question by:pgilfeather
  • 5
  • 3
  • 2
10 Comments
 
LVL 14

Expert Comment

by:dfu23
Comment Utility
You could start with something like

<script type="text/javascript">
    var i = 0;
    window.onload = function() {
        window.setInterval("endExam()", 1000);
    };
    function endExam() {
        i++;
        if (i == 600) { // 600 seconds is 10 minutes
            document.location.href = "timesUp.htm";
        }
    }
</script>
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
 Public m_Timer As System.Timers.Timer

  AddHandler m_Timer.Elapsed, AddressOf TimerTick

  Private Sub TimerTick(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)

  End Sub

Bob
0
 

Author Comment

by:pgilfeather
Comment Utility
How would I put this in my .aspx page.

Do I treat the script part as I would a piece of VB.NET?

and what about the display?

Im not really very sure when it comes to javascript but I know for this kind of feature I really do need to get into a bit of it.

Could you explain a bit further on the code you have supplied.

Thanks very much, I really do appreciate it.

PG
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
Comment Utility
Do you need a display?


In the code-behind page:

Public m_Timer As System.Timers.Timer = New System.Timers.Timer

 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here

    AddHandler m_Timer.Elapsed, AddressOf TimerTick

  End Sub

  Private Sub TimerTick(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)

  End Sub

Bob
0
 

Author Comment

by:pgilfeather
Comment Utility
TheLearnedOne,
could you explain further please?

I am a beginner at this.

cheers

PG
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 14

Expert Comment

by:dfu23
Comment Utility
Ok, basically Javascript is sent with the HTML that is sent to your clients machine ... it is then parsed and run on their machine ...

You should place the <script> tags in between the <head> tags of your document. As far as displaying the time ... how do you want to do it? something that displays text like "10:00" and then ticks down every second ... "9:59", "9:58" etc ... ? or something different?

And then, what needs to happen when it reaches "0:00"? Submit the exam even if they are not done? Or just navigate to another page?
0
 

Author Comment

by:pgilfeather
Comment Utility
You have explained what I want to do exactly.

How can I accomplish this?

PG
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
What do you need explained?

(1) Define a timer variable at the top of the module, above the Page_Load event.

(2) Add an event handler to the variable in the Page_Load event

(3) Set the interval (milliseconds) in the Page_Load event:  m_Timer.Interval = 1000 * 60 * 10  ' 10 minutes.

(3) Add the Timer_Tick event sink below the Page_Load event.  The event handler needs the signature as shown.

Open the web page, view the code behind page, and paste this code into the places indicated.

Bob
0
 

Author Comment

by:pgilfeather
Comment Utility
"9:59", "9:58" etc ... this will do me
0
 

Author Comment

by:pgilfeather
Comment Utility
TheLearnedOne,

yes, I need a display.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now