开发者

JavaScript error when using ASP.NET UpdatePanel

开发者 https://www.devze.com 2023-01-26 17:18 出处:网络
I\'m using an UpdatePanel to swap the ActiveView of a MultiView. In IE开发者_如何学编程6, 7 and 8 and Chrome 7 I get a JavaScript error when the UpdatePanel returns. In Firefox 3.6.1 there is no erro

I'm using an UpdatePanel to swap the ActiveView of a MultiView.

In IE开发者_如何学编程6, 7 and 8 and Chrome 7 I get a JavaScript error when the UpdatePanel returns. In Firefox 3.6.1 there is no error reported (in the error console or in Firebug).

The error is on line 3621 of ScriptResource.axd

function Sys$_ScriptLoader$_loadScriptsInternal() {
    var session = this._currentSession;
    if (session.scriptsToLoad && session.scriptsToLoad.length > 0) {
        var nextScript = Array.dequeue(session.scriptsToLoad);
        var scriptElement = this._createScriptElement(nextScript);

        if (scriptElement.text && Sys.Browser.agent === Sys.Browser.Safari) {
            scriptElement.innerHTML = scriptElement.text;
            delete scriptElement.text;
        }            
        if (typeof(nextScript.src) === "string") {
            this._currentTask = new Sys._ScriptLoaderTask(scriptElement, this._scriptLoadedDelegate);
            this._currentTask.execute();
        }
        else {
            var headElements = document.getElementsByTagName('head');
            if (headElements.length === 0) {
                 throw new Error.invalidOperation(Sys.Res.scriptLoadFailedNoHead);
            }
            else {
line 3621:        headElements[0].appendChild(scriptElement);
            }


            Sys._ScriptLoader._clearScript(scriptElement);
            this._loadScriptsInternal();
        }
    }
    else {
        this._stopSession();
        var callback = session.allScriptsLoadedCallback;
        if(callback) {
            callback(this);
        }
        this._nextSession();
    }
}

JavaScript error when using ASP.NET UpdatePanel

Chrome's Developer tools show that headElements is a NodeList with one element and that scriptElement is an HTMLScriptElement

JavaScript error when using ASP.NET UpdatePanel

What could be the cause of this error? Why is it only apparent in IE and Chrome, and not Firefox?


There was an error in the script that I was outputting in the ScriptManager.RegisterStartupScript. This was causing a runtime error as the browser parsed the JavaScript when the <script> tag was added to the DOM, as suggested by @Rahul in the comments.


gzip compression might also cause this kind of issue for those looking for a solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消