4

I have a long process and I want to show a user a progress bar where I pass a parameter (percentage) to a Javascript function in my Webform with masterpage.

I have this:

<script type="text/javascript"> 
        function updateProgress(percentage) {          
            document.getElementById('ProgressBar').style.width = percentage+"%";
        }
</script>

and:

<div class="progress progress-striped active progress-success" style="height: 43px">
      <div id="ProgressBar" class="progress-bar" role="progressbar" runat="server"
          aria-valuemin="0" aria-valuemax="100" style="width: 0%">
      </div>
</div>

In my code-behind, I have this to pass a parameter to the function:

// Report progress >> ~ 18%                   
string updateProgress = "18";
ClientScript.RegisterStartupScript(this.GetType(), "updateProgress", "updateProgress('" + updateProgress + "');", true);

As I run the code, the progressbar never moves from 0%. I would like to keep updating the percentage completion from code behind until it reaches 100% by calling the function again with new parameters.

I have looked through forums but I cant see what I need to to to make it work.

Any ideas?

7
  • 1
    Your server code registers a script that will be executed when you return a response to the client. In a web application the server and client are disconnected most of the time. It's like sending a letter. The client is waiting for your response, you can't give them status updates as you're writing. Commented Aug 4, 2014 at 13:32
  • good question. Do you access a database in the process? Commented Aug 4, 2014 at 13:32
  • Forgive my lack of expertise when it comes to Javascript. @RobH I'm open to any other ways to achieve what I require. Commented Aug 4, 2014 at 13:35
  • @lalborno. Yes, financial calculations are performed during the process and there are numerous queries to a number of tables. Commented Aug 4, 2014 at 13:36
  • 2
    You don't need SignalR. You can achieve it with WebMethods and JavaScript. Commented Aug 4, 2014 at 13:54

1 Answer 1

10

Try this way

    string updateProgress = "18%";
    ClientScript.RegisterStartupScript(this.GetType(), "updateProgress", "updateProgress('" + updateProgress + "');", true);

Script AS

   <script type="text/javascript">
    function updateProgress(percentage) {
        document.getElementById("ProgressBar").style.width = percentage;
    }
  </script>

ASPX page

   <div class="progress progress-striped active progress-success" style="height: 43px">
        <div id="ProgressBar" runat="server" class="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100"
            style="width: 0px;" >
        </div>
    </div>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.