使用ScriptManager.RegisterStartupScript时出现Javascript错误
注意:以下只是live server上的一个问题。在我所在的地方,一切都很顺利 我的标记中有一个javascript函数,如下所示:使用ScriptManager.RegisterStartupScript时出现Javascript错误,javascript,asp.net,ajax,popup,scriptmanager,Javascript,Asp.net,Ajax,Popup,Scriptmanager,注意:以下只是live server上的一个问题。在我所在的地方,一切都很顺利 我的标记中有一个javascript函数,如下所示: function openNewWin(url) { var x = window.open(url, 'mynewwin', 'width=500,height=500,toolbar=0,scrollbars=0'); x.focus(); } 在按钮单击事件中,我调用以下命令: ScriptMa
function openNewWin(url) {
var x = window.open(url, 'mynewwin', 'width=500,height=500,toolbar=0,scrollbars=0');
x.focus();
}
在按钮单击事件中,我调用以下命令:
ScriptManager.RegisterStartupScript(this, this.GetType(), "OpenWin", "openNewWin('" + url + "')",true);
这不起作用,我在chrome中得到以下信息:
Uncaught SyntaxError: Unexpected identifier ScriptResource.axd:448
_ScriptLoader$_loadScriptsInternal ScriptResource.axd:448
_ScriptLoader$_loadScriptsInternal ScriptResource.axd:453
_ScriptLoader$_loadScriptsInternal ScriptResource.axd:453
_ScriptLoader$_loadScriptsInternal ScriptResource.axd:453
_ScriptLoader$_nextSession ScriptResource.axd:476
_ScriptLoader$_loadScriptsInternal ScriptResource.axd:462
_ScriptLoader$_nextSession ScriptResource.axd:476
_ScriptLoader$loadScripts ScriptResource.axd:372
PageRequestManager$_onFormSubmitCompleted ScriptResource.axd:1480
$type.createDelegate ScriptResource.axd:628
$type.getHandler ScriptResource.axd:4338
raise ScriptResource.axd:7429
WebRequest$completed ScriptResource.axd:7433
Sys.Net.XMLHttpExecutor._onReadyStateChange
在IE中,我得到:
Message: Expected ')'
Line: 1
Char: 51
Code: 0
URI: http://mysite.com/postage/printpostage.aspx
我不知道我的javascript出了什么问题。它在开发中非常有效
更多详细信息:我正在使用ASP.NET WebForms。执行代码的按钮嵌套在UpdatePanel中
谢谢你的帮助
编辑:
我删除了ScriptManager.RegisterStartupScript,并尝试在单击按钮时执行一些简单的操作,但出现了相同的错误。我想是别的原因造成的。我该如何解决这个问题
编辑2:
我从头开始,它看起来像是Scriptmanager.registerstartupscript的任何代码。例如,我尝试了以下方法,得到了相同的问题:
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "AlertError", "alert('Error: " + ex.Message + "');", true);
}
在将启动脚本添加到页面之前是否定义了openNewWin函数?是的,它是-我的html标记中的脚本标记中有它。url变量是否包含单引号?好的,这是最奇怪的事情。我不知道我做了什么使它工作,但我删除了代码,把它放回,使用一个新的按钮,重新启动我的网站,它工作了。