2010-11-25 165 views
1

我正在使用UpdatePanelActiveView換成MultiView使用ASP.NET UpdatePanel時出現JavaScript錯誤

在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(); 
    } 
} 

Uncaught SyntaxError: Unexpected number

Chrome的開發人員工具顯示,headElementsNodeList一個元素和scriptElementHTMLScriptElement NodeList and ScriptElement

可能是這個錯誤的原因是什麼?爲什麼只在IE和Chrome中顯而易見,而不是Firefox?

+3

最有可能的是,在代碼中的東西。你可以在你正在交換的地方分享代碼嗎? – 2010-11-29 03:00:48

回答

4

我在ScriptManager.RegisterStartupScript中輸出的腳本中存在錯誤。正如@Rahul在註釋中所建議的那樣,當<script>標記添加到DOM時,瀏覽器解析JavaScript會導致運行時錯誤。

+0

非常感謝這個問題和答案。我在我的腳本中錯過了一個撇號```,這實際上導致了一個坐在語法錯誤的地方的數字。 – Oliver 2013-06-01 10:08:19