使用 ASP.NET UpdatePanel 时出现 JavaScript 错误

Gre*_*g B 1 asp.net updatepanel asp.net-ajax asp.net-3.5

我正在使用 anUpdatePanel来交换ActiveViewa 的MultiView

在 IE6、7 和 8 以及 Chrome 7 中,当 UpdatePanel 返回时,我收到 JavaScript 错误。在 Firefox 3.6.1 中,没有报告错误(在错误控制台或 Firebug 中)。

错误位于 ScriptResource.axd 的第 3621 行

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

未捕获的语法错误:意外的数字

Chrome 的开发者工具显示,这headElements是一个NodeList只有一个元素的元素,这scriptElement是一个HTMLScriptElement 节点列表和脚本元素

导致此错误的原因可能是什么?为什么它只在 IE 和 Chrome 中明显,而在 Firefox 中不明显?

Gre*_*g B 5

我在 .txt 文件中输出的脚本中有一个错误ScriptManager.RegisterStartupScript<script>正如 @Rahul 在评论中所建议的,当将标签添加到 DOM 时,浏览器会解析 JavaScript,这会导致运行时错误。