5,445,109 members and growing! (15,179 online)
Email Password   helpLost your password?
Web Development » ASP.NET » Howto     Beginner License: The Code Project Open License (CPOL)

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

By Pascal Ganaye

This article explain how to fix a bug in the Asp.Net framework when using callback panels.
C#, VB (VB 7.x, VB 8.0, VB 9.0, VB 6, VB), HTML, Dev

Posted: 3 Jul 2008
Updated: 3 Jul 2008
Views: 2,330
Bookmarked: 3 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
6 votes for this Article.
Popularity: 2.61 Rating: 3.36 out of 5
1 vote, 16.7%
1
1 vote, 16.7%
2
1 vote, 16.7%
3
1 vote, 16.7%
4
2 votes, 33.3%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

I recently hit a runtime error bug recently 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 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.

// 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; 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 to add a var keyword to make the variable local.
Looking on the internet you can find that some people suggest also 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.
<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++) {
        qcallbackObject = __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 overrides 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)

About the Author

Pascal Ganaye


I am a French programmer.
These days I spent most of my time around the Dotnet framework.
I love the code project website and I use it nearly every working day.

Occupation: Web Developer
Location: United Kingdom United Kingdom

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
  (Refresh) 
Subject  Author Date 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 3 Jul 2008
Editor:
Copyright 2008 by Pascal Ganaye
Everything else Copyright © CodeProject, 1999-2008
Web11 | Advertise on the Code Project