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
178 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
ID: 12180594
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
ID: 12180666
 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
ID: 12180677
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
ID: 12180705
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
ID: 12180711
TheLearnedOne,
could you explain further please?

I am a beginner at this.

cheers

PG
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:dfu23
ID: 12180730
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
ID: 12180753
You have explained what I want to do exactly.

How can I accomplish this?

PG
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12180759
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
ID: 12180809
"9:59", "9:58" etc ... this will do me
0
 

Author Comment

by:pgilfeather
ID: 12180902
TheLearnedOne,

yes, I need a display.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

862 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

23 Experts available now in Live!

Get 1:1 Help Now