Click here to Skip to main content
15,911,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've created a user control that does some jquery in document.ready to handle a paging solution. However, one of the pages it needs to be located, the user control isn't visible to start with and an async postback is used to display it.

I've discovered that this prevents the code from within ready() to be executed. I found a useful blog which gave the following snippet to be added to the main page:

C#
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
     function EndRequestHandler(sender, args) {
         if (args.get_error() == undefined) {
                alert('async postback event caught');
         }
     }


which means I can now catch the end of the async postback. However, I still can't see how to call the code contained within the user control (web dev isn't my main skill area). Can anyone point me in the right direction?

TIA

Dave
Posted

jQuery is a sort of wrapper over a traditional JavaScript. It can be used as Javascripts are used to trap things.
Looks like you are talking of trapping an UpdatePanel async update.

You can catch the async update of update panel as:
JavaScript
function EndRequestHandler(sender, eArgs) 
{            
   /*
   1. Alert/Message if any after update
   2. Error handling if any
   3. Scroll position set again
   4. Focus/UI update if any
   */
   //Example
   if (eArgs.get_error() == null)
   {
      // Do all the stuffs needed after update through JavaScript here. 
      //1. Alert / Show window / Show Dialog
      //alert("Update was successful");
      //2. Page Controls accessed via JavaScript
      document.getElementById("lblTest").innerText = "Update Successful";
      //3. Page scrolls can be set if needed
      //Set Scroll Position
   }
   else
   {
      // There was an error in the update panels update 
      // caught here and message displayed via JavaScript               
      document.getElementById("lblTest").innerText = 
              "There was an error in update:"+eArgs.get_error().message;
   }
} 

For details, have a look at this article: JavaScript Access to Page Controls after Ajax Update (via Update Panel)[^]
 
Share this answer
 
of course it doesnt, the document doesnt get re-processed like..
u gotta use a success: of the async function to do your code that u wanna do when the async is finished..
i.e.

var xhr = $.ajax({

        ajaxrequiredarguements......

        success: function( data, status ) {

            :: Call your method in here ::

        },

        end....

    });
 
Share this answer
 
you need to add your jquery in the pageLoad() function.
This will solve your Ajax update panel problem also. Try below code.

JavaScript
function pageLoad()
{
//...Add jQuery code here....
}


If this helped you then please Vote and mark it as answer.
 
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