0

クラスに次の 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」というエラーをログに記録します。

コードの何が問題になっていますか?

4

1 に答える 1

1

CRLFsalah.Messageが含まれています。トリミングするか、エスケープします。

RegisterStartupScriptまたは、それを行うメソッドでラップします。

于 2013-02-14T08:17:23.700 に答える