Search code examples
jquery.netupdatepanel

Run JQuery after Specific updatePanel fires


I have a script that runs once an update panel fires: Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); function EndRequestHandler(sender, args) { initDropSearch(); } function initDropSearch() {

    var search = jQuery("#searchBar div.productSearchFilter");

    if (search.length > 0) {

        var grid = search.find("table.gridView");

        if (search.next().val() != "open") {

            search.animate({
                height: ['toggle', 'easeOutBounce'],
                opacity: 'toggle'
            }, 1000)

            .next().val("open");

        } else {

            search.show();

        }
    }
}

Once the results of a search have loaded, the container drops down and bounces.

It works perfectly - that is until another update panel is triggered on the same page - in which case the search panel opens again.

What I need to do is only run the script when a specific updatePanel fires.

Is there a way to do this?


Solution

  • Do the sender or args contain data about the UpdatePanel that triggered the EndRequestHandler?

    If so just check which one triggered it and only fire your code based on that.

    function EndRequestHandler(sender, args) {
        if (((UpdatePanel)sender).ID == "UpdatePanel1") {
            initDropSearch(); 
        }
    }