Click here to Skip to main content
15,889,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I call a jQuery function from Default.aspx.cs?

Default.aspx.cs
C#
var Progress = "20";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "scr", "setProgress(" + Progress + ");", true); 

Error Code:
JavaScript runtime error: 'setProgress' is undefined

Default.aspx
HTML
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            function setProgress(progress) {
                var progressBarWidth = progress * $(".container").width() / 100;
                $(".progressbar").width(progressBarWidth).html(progress + "% ");
            }
            (function ($) {
                $.fn.progressbar = function (options) {
                    var settings = $.extend({
                        width: '300px',
                        height: '25px',
                        color: '#0ba1b5',
                        padding: '0px',
                        border: '1px solid #ddd'
                    }, options);

                    //Set css to container
                    $(this).css({
                        'width': settings.width,
                        'border': settings.border,
                        'border-radius': '5px',
                        'overflow': 'hidden',
                        'display': 'inline-block',
                        'padding': settings.padding,
                        'margin': '0px 10px 5px 5px'
                    });

                    // add progress bar to container
                    var progressbar = $("<div></div>");
                    progressbar.css({
                        'height': settings.height,
                        'text-align': 'right',
                        'vertical-align': 'middle',
                        'color': '#fff',
                        'width': '0px',
                        'border-radius': '3px',
                        'background-color': settings.color
                    });

                    $(this).append(progressbar);

                    this.progress = function (value) {
                        var width = $(this).width() * value / 100;
                        progressbar.width(width).html(value + "% ");
                    }
                    return this;
                };

            } (jQuery));

        });
    </script>
Posted
Updated 10-Oct-14 10:19am
v2

1 solution

Move your setProgress function outside of the document.ready function.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900