0

I have this C# code in my class:

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);
        }
    }

which produce this code

 <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>

But the alert box doesn't show up, and Chrome logs an error "Uncaught SyntaxError: Unexpected token ILLEGAL "

What's wrong with my code?

1 Answer 1

1

Your salah.Message contains a CRLF. Trim it or escape it.

Or wrap RegisterStartupScript in a method that does it.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I replace some parts of the code with this String cstext = "alert('" + salah.Message.Replace("\n", "") + "');";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.