Click here to Skip to main content
15,880,972 members
Articles / Web Development / ASP.NET
Tip/Trick

JavaScript function to be called after UpdatePanel refreshes

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
16 Jul 2011CPOL 14.8K   2  
A method to call a function in JavaScript after each response.

I was searching for a method to call a function in JavaScript after each response. I found a method to do this:

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded


I also made a function to manage the loading of DOM objects.
JavaScript
$.PlanetAspNet.setReady('.hint',function(hint){
    hint.each(function(){
        var $span = $(this);
        $span.siblings('input')
             .focus(function(){ $span.show()})
             .blur(function(){ $span.hide()});

Here is the JavaScript function after UpdatePanel refreshes. In this case, the function will be called on document ready and after each DOM object is created after ASPNET Async.


JavaScript
$.PlanetAspNet = {
    options: [],
    PageLoadedHandler: function(sender,e){
        if (e._panelsUpdated.length==0){
            $.PlanetAspNet.Ready(document,e);
        }else{
            $.each(e._panelsUpdated,function(){
                $.PlanetAspNet.Ready(this,e);
            });
        };
    },
    setReady: function(selector,fn){
        $.PlanetAspNet.options.push({selector:selector,fn:fn});
        return $.PlanetAspNet.options;
    },
    Ready: function(item,e){
        $.each($.PlanetAspNet.options,function(){
            var o = $(item).find(this.selector);
            if (o.length>
0) this.fn(o,item,e);
        });
        return item;
    }
};

I hope this helps.

License

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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --