0

I am new to Jquery. The problem I am facing is, I am able to call alertbox from code behind but when I replace alertbox with Jquery function, I am getting error "Microsoft JScript runtime error: 'loadPopupBox' is undefined"

This same function loadPopupBox() works perfectly fine when run at "document ready"

    <script type="text/javascript">

   function myFunction() {
        loadPopupBox();  //This doesn't work while calling from code behind
        //alert("Hi");   // This works fine with code behind
    }

    $(document).ready(function () {


        loadPopupBox();  //This works fine with document load

        function loadPopupBox() {    
            $('#popup_box').fadeIn("slow");
            $("#container").css({ 
                "opacity": "0.3"
            });
        }
    });
</script>

CODE BEHIND IS AS FOLLOWS

protected void Button1_Click(object sender, EventArgs e)
{
    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "myFunction();", true);
}

Any help is greatly appreciated.

Regards Nikunj

1 Answer 1

0

Stop defining function inside the $(document).ready. if you want to call a function on page load, define it outside the $(document).ready and then call it inside that.

Modify your code like this and it'll worked fine:

function myFunction() {
    loadPopupBox();
}

$(document).ready(function () {
    loadPopupBox();
});

function loadPopupBox() {    
    $('#popup_box').fadeIn("slow");
    $("#container").css({ 
        "opacity": "0.3"
    });
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.