Pass parameter to Javascript function from ASP code behind

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

I have it:

<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, I have this to pass a parameter to a function:

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

When I run the code, the progress indicator never moves from 0%. I would like to continue to update the percentage filling from the code until it reaches 100%, again calling the function with new parameters.

I was browsing the forums, but I don’t see what I need to get it to work.

Any ideas?

+4
source share
1 answer

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

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

All Articles