Click here to Skip to main content
15,881,588 members
Articles / Web Development / HTML

Fixing "Microsoft JScript runtime error: '__pendingCallbacks[...].async' is null or not an object"

Rate me:
Please Sign up or sign in to vote.
4.32/5 (17 votes)
1 Jun 2009CPOL1 min read 66K   13   9
This article explains how to fix a bug in the ASP.NET Framework when using callback panels.

Image 1

Introduction

I recently hit a runtime error bug while using ASP.NET callback components.

There is a bug in the Microsoft ASP.NET standard library.

Fixing the bug is rather complicated because you have to change the source code you don't have access to.

I could not find a complete step by step article on how to fix the error, this is why I decided to post the entire code.

Background

When running a page, I would hit an error:

"Microsoft JScript runtime error: '__pendingCallbacks[...].async' 
					is null or not an object"

The error occurs on this line.

JavaScript
// ORIGINAL CODE FROM MICROSOFT 
function WebForm_CallbackComplete() {
    for (i = 0; i < __pendingCallbacks.length; i++) {
        callbackObject = __pendingCallbacks[i];
        if (callbackObject && callbackObject.xmlRequest && 
		(callbackObject.xmlRequest.readyState == 4)) {
            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);
            }
        }
    }
} 

The Problem

It seems that the error is in the for (i=0; and is the core of the problem. The i variable is a global variable and it can get changed within the loop.

The fix is to add a var keyword to make the variable local.
Looking on the internet, you can find that some people also suggest to move the WebForm_ExecuteCallback lower in the loop.

The Fix

In order to fix your page, you just have to insert this code in the beginning of your page. I personally put it in the body.
JavaScript
<script type="text/javascript">
//<![CDATA[
var GlvDelayedNextPageNo;

function WebForm_CallbackComplete_SyncFixed() {
     // the var statement ensure the variable is not global
     for (var i = 0; i < __pendingCallbacks.length; i++) {
        callbackObject = __pendingCallbacks[i];
        if (callbackObject && callbackObject.xmlRequest && 
			(callbackObject.xmlRequest.readyState == 4)) {
            // SyncFixed: line move 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);
            }
            // SyncFixed: the following statement has been moved down from above;
            WebForm_ExecuteCallback(callbackObject);
        }
    }
}

var OnloadWithoutSyncFixed = window.onload;

window.onload = function Onload(){
    if (typeof (WebForm_CallbackComplete) == "function") {
        // Set the fixed version
        WebForm_CallbackComplete = WebForm_CallbackComplete_SyncFixed;
        // CallTheOriginal OnLoad
        if (OnloadWithoutSyncFixed!=null) OnloadWithoutSyncFixed();
    }
}
//]]>
</script> 

Points of Interest

This was because while overloading the onload function, you could change the behaviour of the rest of your components.

The right method is to override the onload but within the new onload, call the previous one.

This is not rocket science, but also probably not obvious for everyone.

License

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


Written By
Software Developer (Senior)
France France
I am a French programmer.
These days I spend most of my time with the .NET framework, JavaScript and html.

Comments and Discussions

 
GeneralMy vote of 5 Pin
shoaibiqbal@live.com13-Nov-14 3:06
shoaibiqbal@live.com13-Nov-14 3:06 
QuestionThanks for posting such a valuable fix Pin
Vijai Prakash Maurya5-Dec-11 23:42
Vijai Prakash Maurya5-Dec-11 23:42 
GeneralThanks Pin
Vinay Bansal30-Jan-11 17:22
Vinay Bansal30-Jan-11 17:22 
GeneralGreat Pin
ravendawson21-Nov-10 1:57
ravendawson21-Nov-10 1:57 
GeneralMy vote of 4 Pin
Pieter Alec Myburgh12-Aug-10 22:29
Pieter Alec Myburgh12-Aug-10 22:29 
Thanks man.. I just love fixing Microsoft's crap with a quick and simple piece of javascript!
GeneralThanks Pin
reza toorani20-Jul-10 8:26
reza toorani20-Jul-10 8:26 
GeneralHi Thank you Pin
kkarimi9111-Apr-10 22:51
kkarimi9111-Apr-10 22:51 
GeneralTypo Pin
schweeneh22-Sep-08 10:07
schweeneh22-Sep-08 10:07 
GeneralRe: Typo Pin
Pascal Ganaye1-Jun-09 13:31
Pascal Ganaye1-Jun-09 13:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.