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
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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