user1263981
user1263981

Reputation: 3147

Pass value to Jquery function from code behind

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.

Upvotes: 0

Views: 5179

Answers (3)

Shankaranand
Shankaranand

Reputation: 67

You may want to try:

ScriptManager.RegisterClientScriptBlock(Me.Page, Me.Page.GetType(), "progressbar", "ShowProgressBar("+ 35 +");", True)

Upvotes: 0

Saravana Kumar
Saravana Kumar

Reputation: 3729

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
     });
 }

Upvotes: 1

prog1011
prog1011

Reputation: 3495

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(); }); });

Upvotes: 0

Related Questions