live wid knowledge :)

'__pendingCallbacks[...].async' is null or not an object: callback async[i]...FIX :)

In my prior both articles about CALLBACK, which considered as Article of the Day @ www.asp.net recently might have problem:

Here i would like to talk about async indexer problem and of course solution as well :)

PROBLEM 1: '__pendingCallbacks[...].async' is null or not an object

EXPLANATION: if you debug then error message says, there is some problem with indexer [i] of async callback, hmmm you might not get that error message after using callback but developing other modules/part of the website you might get such error 1 day as i did :D, so if you are brainy enough, you must think something new i did which cause this ripple effect and go ahead to look for that what exactly i did and if you keep thinking with reading that error message carefully, you will get to know: somewhere you are using "i" variable and that variable is not being getting out of scope so mixing with "i" variable of callback async[i] and making problem.

Solutions:
1) solution is simple: follow standards and never make any variable name of single character rather use: anyhow either change your variable name from "i" to intCounter or anything u want

2) take care of your variable scope, so it wont mixup with variable "i"

3) use the following code/snippet: if you want to keep using your "i" variable in your code (may be you have used that at many places and don't wanna mess up with your existing code):

<script type="text/javascript">
function WebForm_CallbackComplete

_SyncFixed() {
  // SyncFix: the original version uses "i" as global thereby resulting in javascript errors when "i" is used elsewhere in consuming pages
  for (var i = 0; i < __pendingCallbacks.length; i++) {
   callbackObject = __pendingCallbacks[ i ];
  if (callbackObject && callbackObject.xmlRequest && (callbackObject.xmlRequest.readyState == 4)) {
   // the callback should be executed after releasing all resources
   // associated with this request.
   // Originally if the callback gets executed here and the callback
   // routine makes another ASP.NET ajax request then the pending slots and
   // pending callbacks array gets messed up since the slot is not released
   // before the next ASP.NET request comes.
   // FIX: This statement has been moved below
   // WebForm_ExecuteCallback(callbackObject);
   if (!__pendingCallbacks[ i ].async) {
     __synchronousCallBackIndex = -1;
   }
   __pendingCallbacks[i] = null;

   var callbackFrameID = "__CALLBACKFRAME" + i;
   var xmlRequestFrame = document.getElementById(callbackFrameID);
   if (xmlRequestFrame) {
     xmlRequestFrame.parentNode.removeChild(xmlRequestFrame);
   }

   // SyncFix: the following statement has been moved down from above;
   WebForm_ExecuteCallback(callbackObject);
  }
 }
}
window.onload = function Onloaad(){
if (typeof (WebForm_CallbackComplete) == "function") {
  // set the original version with fixed version
  WebForm_CallbackComplete = WebForm_CallbackComplete_SyncFixed;
}
}
</script>

 

Comments

Jaco Boersema said:

Thankyou for the explanation and the script. It halped tremendously in solving the problem.

Regards.

# July 5, 2008 9:05 AM

Shawn Cutler said:

I would like to thank you for this little bit of info. I've been chasing my tail trying to figure this out for a few hours now and decided to look around the web to find a solution. Your solution was a big time saver. Thanks again!!

# July 14, 2008 2:58 PM

Curry said:

Wow Thx

# October 10, 2008 5:26 AM

Sriraj Madhavan said:

Life Saver actually......Thanks alot Muhammad:-)

# February 13, 2009 5:48 AM

Avdhoot Saple said:

Thanks a lot, great solution !

# April 3, 2009 12:22 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)