Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在.net中使用Javascript嵌入代码块时出错_Javascript_Asp.net - Fatal编程技术网

在.net中使用Javascript嵌入代码块时出错

在.net中使用Javascript嵌入代码块时出错,javascript,asp.net,Javascript,Asp.net,当我这样给出时,我得到一个未终止的字符串常量 <input type="button" name="cancel" value="Close" onClick="javascript:top.location.href = '../admin/page.aspx?curTab=<%=curTab%>';"> 我在下面代码行的“&”处得到了未终止的字符串常量和语法错误 <input type="button" name="cancel" value="Clos

当我这样给出时,我得到一个未终止的字符串常量

 <input type="button" name="cancel" value="Close" onClick="javascript:top.location.href = '../admin/page.aspx?curTab=<%=curTab%>';">

我在下面代码行的“&”处得到了未终止的字符串常量和语法错误

<input type="button" name="cancel" value="Close" onClick="javascript:top.location.href = 'plan.aspx?res=<%=Request("res")%>&Count=<%=Request("count")%>';">

有人能告诉我为什么会发生这种情况吗?我想这是因为嵌入了代码块。请帮帮我


提前谢谢

我不认为这种情况可以内联处理。尝试预先准备要在onclick='[]中呈现的文本。例如,对于您的第一句话:

    <%
    var bb = String.Format("javascript:top.location.href = \"../admin/page.aspx?curTab={0}\";", curTab);
%>
<input type="button" name="cancel" value="Close" onClick='<%=bb%>'>


类似地,您可以看到要转义的标准C#语法,以及第二条语句。

这段代码在ASPX中吗?@MichaelLiu:是的。它在aspx中。你能把前面的几行也贴出来吗?谢谢你的帮助。我已经试过了。现在我也得到了相同的错误“unterminatedstringconstant”。它给了你什么错误吗?