Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I tried to make countdown timer in my webform but it not working. I try to go according this link: Using Timer on Examination Web page ASP.NET || C#.NET || Hindi - YouTube[^] He use C# I use VB. I would like to set timer on eg:60second and if time expire then click on button and set again timer to 60s and still arround. Can you help me please?

What I have tried:

<%@ Page Language="VB" Debug="true" validateRequest="false"  CodeFile="Monitoring.aspx.vb" Inherits="Monitoring"%>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Monitoring</title>
    </head>
<body onload="startcountdown(20);" style="background-image:url('Image/obr.jpg');" >   
    
    <script>
    function startCountdown(timeLeft) {
        var interval = setInterval( countdown, 1000 );
        update();

        function countdown() {
            if ( --timeLeft > 0 ) {
                update();
            } else {
                clearInterval( interval );
                update();
              //Show the alert message , change the message as per your need
              alert('Time Up!');
                completed();
            }
        }

        function update() {
            hours   = Math.floor( timeLeft / 3600 );
            minutes = Math.floor( ( timeLeft % 3600 ) / 60 );
            seconds = timeLeft % 60;

            document.getElementById('lbltimer').innerHTML = '' + hours + ':' + minutes + ':' + seconds;
        }

        function completed() {
          //Change the url here
            window.location = "http://www.asp.net";
        }
    }
</script>

    <form id="form2" runat="server">
Posted
Updated 28-Nov-21 23:21pm
Comments
Richard Deeming 24-Nov-21 3:40am    
The choice of C# vs VB.NET is irrelevant - both of you are using Javascript, which is the only option for code that runs on the client.

You haven't explained what the problem is, nor what you have tried, nor where you are stuck.
Member 15251555 24-Nov-21 7:45am    
Nothing happens at all, no timer is set on the label, as if the function was skipped.

Quote:
HTML
onload="startcountdown(20);"
JavaScript
function startCountdown(timeLeft) {
Javascript is case-sensitive. Your function is called startCountdown, but you try to call startcountdown.

If you check your browser's developer console, you will see an error telling you that the function startcountdown doesn't exist.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900