nathaniel
nathaniel

Reputation: 1145

ASP.NET 2.0 callbacks not working correctly in Firefox

I've implemented a .NET Web control that uses the callback structure implemented in ASP.Net 2.0. It's an autodropdown control, and it works correctly in IE 6.0/7.0 and Google Chrome. Here's the relevant callback function:

function ReceiveServerData(args, context)
{
document.getElementById(context).style.zIndex = 300;
document.getElementById(context).style.visibility = 'visible';
document.getElementById(context).innerHTML = args;
fixHover(context);
}

In Firefox, "args" is always the same data, so the innerHTML of the <div> that is the display for my dropdown always shows the same items. I've doublechecked my client-side code, and the right information is being sent client->server and in return server-> client.

Of note, in the "WebForm_DoCallback" function created by the .NET framework, the following snippet is getting called:

if (setRequestHeaderMethodExists) {
xmlRequest.onreadystatechange = WebForm_CallbackComplete;
callback.xmlRequest = xmlRequest;
xmlRequest.open("POST", theForm.action, true);
xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlRequest.send(postData);
return;
}

and the callback function ReceiveServerData is called both on xmlRequest.open("POST", theForm.action, true); and xmlRequest.send(postData);. I wonder if this is causing an error, but I'm at the end of my debugging skills.

Edited to add -- ReceiveServerData is not being called twice the very first time I use the dropdown -- in fact, the dropdown works correctly for the very first keystroke. It stops working, and doubles the callback with old return data, after the first keystroke.

Upvotes: 2

Views: 2160

Answers (3)

Ken Smith
Ken Smith

Reputation: 20445

For what it's worth, the MS AJAX Function.createCallback() doesn't seem to work correctly in FireFox. See this post here, with repro code:

Function.createCallback doesn't pass context correctly in FireFox

It appears that the context variable loses its state when it's passed to the callback function.

Upvotes: 1

Brendan Kowitz
Brendan Kowitz

Reputation: 1795

I think you need to provide more information, it's probably unlikely that this problem is because of asp.net's built-in js. How is the event being set up to catch keystrokes, are you accidently adding events? How it the scriptservice being called? Just double check all the basics to make sure it's not something crazy and simple like that.

Upvotes: 0

Atanas Korchev
Atanas Korchev

Reputation: 30671

I am not sure if this would help but I have patched the ASP.NET 2.0 callbacks like this (minified code):

function WebForm_CallbackComplete()
{
    for(var i=0; i< __pendingCallbacks.length;i++)
    {
        var _f3=__pendingCallbacks[i];
        if(_f3 && _f3.xmlRequest && (_f3.xmlRequest.readyState==4))
        {
            __pendingCallbacks[i]=null;
            WebForm_ExecuteCallback(_f3);
            if(!_f3.async)
            {
                __synchronousCallBackIndex=-1;
            }
            var _f4="__CALLBACKFRAME"+i;
            var _f5=document.getElementById(_f4);
            if(_f5)
            {
                _f5.parentNode.removeChild(_f5);
            }
        }
    }
}

If you check the actual implementation of WebForm_CallbackComplete you would spot a few issues. You can try pasting that JavaScript within your form tag to see if it would make a difference.

Upvotes: 0

Related Questions