2010-11-25 167 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