Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.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
C# ASP.net警报框使用RegisterStartupScript,生成javascript代码,但有错误_C#_Asp.net_Alert - Fatal编程技术网

C# ASP.net警报框使用RegisterStartupScript,生成javascript代码,但有错误

C# ASP.net警报框使用RegisterStartupScript,生成javascript代码,但有错误,c#,asp.net,alert,C#,Asp.net,Alert,我班上有一个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

我班上有一个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记录了一个错误“uncaughtsyntaxerror:unexpectedtoken-liquired”


我的代码有什么问题吗?

您的
salah。消息包含CRLF。修剪它或逃脱它


或者将RegisterStartupScript
包装到一个方法中。

谢谢!我用以下内容替换代码的某些部分:
String cstext=“alert('”+salah.Message.replace(“\n”,”)+“);”