1

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

In IE6, 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();
    }
}

Uncaught SyntaxError: Unexpected number

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

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

1
  • 3
    Most likely, something in the code. Can you share the code where you are doing the swapping? Commented Nov 29, 2010 at 3:00

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for this question and the answer. I was missing an apostrophe ' in my script which in fact led to a number sitting there in a syntactically wrong place.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.