0

I have the following javascript code:

<script type="text/javascript" language="javascript">
        $(document).ready(
            function () {
                // THIS IS FOR HIDE ALL DETAILS ROW
                $(".SUBDIV table tr:not(:first-child)").not("tr tr").hide();
                $(".SUBDIV .btncolexp").click(function () {
                    $(this).closest('tr').next('tr').toggle();
                    //this is for change img of btncolexp button
                    if ($(this).attr('class').toString() == "btncolexp collapse") {
                        $(this).addClass('expand');
                        $(this).removeClass('collapse');
                    }
                    else {
                        $(this).removeClass('expand');
                        $(this).addClass('collapse');
                    }
                });

                function expand_all() {
                    $(this).closest('tr').next('tr').toggle();
                    };
            });

    </script>

I want to call expand_all function via code-behind .

I know I can use something like this, but it does not work and I don't understand used parameters:

ScriptManager.RegisterStartupScript(Me, GetType(String), "Error", "expand_all();", True)

Can you help me?

1
  • As for the parameters used, they hide that stuff in the documentation ;) Commented Feb 2, 2015 at 10:20

2 Answers 2

1

Because you have your expand_all function defined within anonymous $.ready event context. Put your code outside and it should work.

function expand_all(){
    alert('test B');
}
$(document).ready(
    function () {
        // this won't work
        function expand_all() {
            alert('test A');
        };
    });


// will show test B
expand_all();

check this:

http://jsfiddle.net/jrrymg0g/

Sign up to request clarification or add additional context in comments.

Comments

1

Your method expand_all only exists within the scope of the function inside $(document).ready(...), in order for you to call it from ScriptManager.RegisterStartupScript it needs to be at the window level, simply move that function outside the $(document).ready(...)

<script type="text/javascript" language="javascript">
    $(document).ready(
        function () {
           ....                
        });

    function expand_all() {
           $(this).closest('tr').next('tr').toggle();
    };
</script>

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.