0

I am using Jquery progress bar control on asp.net form to show the percentage of completed work for inspector. Here is the client side function for progress bar.

    <script>
        $(function () {
            $("#progressbar").progressbar({
                value: 37
            });
        });
    </script>

    <form id="form1" runat="server">
       <div id="progressbar"></div>
    </form>

Is there any way to set progress bar value from code behind page? Values are read from database.

user1263981
  • 2,953
  • 8
  • 57
  • 98

3 Answers3

1

You can use registerstartupscript to inject the script from ASP.NET code behind files.

myScript = "\n<script type=\"text/javascript\" language=\"Javascript\" id=\"EventScriptBlock\">\n";
        myScript += "ShowProgressBar(35);"; //35 is dynamic value
        myScript += "\n\n </script>";
     Page.ClientScript.RegisterStartupScript(this.GetType(), "myKey", myScript, false);

JavaScript Code

function ShowProgressBar(value) 
{
    $("#progressbar").progressbar({
         value: value
     });
 }
Saravana Kumar
  • 3,669
  • 5
  • 15
  • 35
0

Try below steps

  1. First set the DB value to hidden field on page load. like (HiddenFieldID.value="37" // from DB)
  2. Use the hidden field value to set the value to progress bar in js function as below.

$(function () { $("#progressbar").progressbar({ value: $("#<%= HiddenFieldID.ClientID %>").val(); }); });

prog1011
  • 3,425
  • 3
  • 30
  • 57
0

You may want to try:

ScriptManager.RegisterClientScriptBlock(Me.Page, Me.Page.GetType(), "progressbar", "ShowProgressBar("+ 35 +");", True)
Dave
  • 434
  • 5
  • 22