Can I put a timer on an aspx page?

Posted on 2008-11-06
Last Modified: 2012-05-05
In VB.NET, how can I run a timer on a page which redirects the user to another page when the time runs out?  This is for a test-taking web app in which I want the test ended after a period of time and the user given her score.
Question by:Stovetop
    LVL 25

    Accepted Solution

    You can do that in javascript. This example supposes that you desire to redirect at 5 seconds; replace with number of seconds that you want.

    First, declare this function in javascript between your <HEAD> tag:
    <script type="text/javascript">
        var seconds = -1;
        var redirect_at_seconds_number = 5;

        function Timer() {
            if(seconds == redirect_at_seconds_number) {
                document.location.href = 'new_page.aspx'; //or the location that you want
            } else {
                setTimeout("Timer()", 1000);

    Second, in the <body> declaration of your page, attach this parameter:
    <body onload="Timer()">

    That's all. Hope that helps.

    Author Closing Comment

    Tremendous. Awesome. Fabulous.  Thanks so much.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    746 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

    19 Experts available now in Live!

    Get 1:1 Help Now