我班上有这个C#代码:
private static void error_message(Sybase.Data.AseClient.AseException salah)
{
Page executingPage = HttpContext.Current.Handler as Page;
Type cstype = HttpContext.Current.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = executingPage.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
{
String cstext = "alert('" + salah.Message + "');";
cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);
}
}
生成此代码
<script type="text/javascript">
//<![CDATA[
alert('ua_services not found. Specify owner.objectname or use sp_help to check whether the object exists (sp_help may produce lots of output).
');//]]>
</script>
但是警告框没有显示,Chrome会记录错误“Uncaught SyntaxError:Unexpected token ILLEGAL”
我的代码出了什么问题?
答案 0 :(得分:1)
您的salah.Message
包含CRLF。修剪它或逃脱它。
或者在执行此操作的方法中包装RegisterStartupScript
。