How to automatically redirect to next page after progress bar finish loading

Donald Symmons 3,066 Reputation points
2025-12-03T18:17:55.22+00:00

How can I create a progress bar that will be loading, and after it finishes loading, it will automatically redirect to next page after 10 seconds?

Here is what I tried, although what I've been able to get is a button such that when the button is clicked, it starts counting and then redirects to another page

I want to create progress bar that will be loading and once it finishes loading, it redirects to another page, using C#

thank you.

HTML

<form id="form1" runat="server" style="background-image: src()">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
       <div style="z-index: 1; left: 15px; top: 18px; position: absolute; height: 63px; width: 284px">  
            <input type="button" value="Redirect to another Page" onclick="RedirectAfterDelayFn()" style="border-width: thick; border-style: double; background-color: #FFFFFF; height: 40px; width: 215px;" />  
            <br />  
            <br />  
            <div id="CountDown" style="display: none">  
                You will be redirected after  
                <br />  
                <span id="CountDownLabel"></span> seconds.  
            </div>  
        </div>  
    </form>

JavaScript

<script type="text/javascript">  
        function RedirectAfterDelayFn() {
            var seconds = 5;
            var dvCountDown = document.getElementById("CountDown");
            var lblCount = document.getElementById("CountDownLabel");
            dvCountDown.style.display = "block";
            lblCount.innerHTML = seconds;
            setInterval(function () {
                seconds--;
                lblCount.innerHTML = seconds;
                if (seconds == 0) {
                    dvCountDown.style.display = "none";
                    window.location = "Home.aspx";
                }
            }, 1000);
        }
    </script>  


Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 81,971 Reputation points Volunteer Moderator
    2025-12-03T20:56:36.4766667+00:00

    Use progress element and update the value in your timer

    <progress id="progress" value="50" max="100"></progress>
    
    
    document.getElementById(“progress”).value = (5-seconds) * 20;
    

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.