Bbb
Bbb

Reputation: 649

Asp and javascript error : Message: Expected ')'

I know this has been asked before and I've tried to use those solutions against my error, but I cannot get it to work using the solutions to past similar questions. The error message is that it expects a ')' . I've tried adding and removing parenthesis as well as removing single and double quotes but it still errors out each time?

protected void btnTestCS_Click(object sender, EventArgs e)
{

string result1 = "Failed: The samAccountName IdentityType must be in the form \"domainname\\userName\", \"machinename\\userName\", or \"userName\". | NN-NN-NN-01.NN.NN.NNNNN.NNN | CN=^sharing,OU=xxx_xxxxxx,OU=xxxxx,OU=xxxx,OU=xxx,OU=xxxxx,DC=xx,DC=xx,DC=xxx,DC=xxxxx)";
ScriptManager.RegisterStartupScript(Page, this.GetType(), "errorRunExchangeShellMultiCommandsss", "javascript:showDialogError(" + result1 + ")" , true);

}

    function showDialogError(results) {
        results = results.replace("'", "\\'");
        results = results.replace("\"", "");
        $("#dialogFailureText").text(results);
        $("#dialogFailure").dialog({
            modal: true,
            title: 'Something went wrong',
            text: results,
            buttons: {
                OK: function () {
                    $(this).dialog("close");
                }
            }


        });
    }

Upvotes: 0

Views: 159

Answers (3)

Bbb
Bbb

Reputation: 649

I had multiple issues with my code, I had to add beginning and ending quotes in this part of the code (\"" + returnValue + "\")" . Then I had to replace any other double quotes inside of the error message string with single quotes as seen below and replace the single slash (which javascript read as a \u) with double slashes because Javascript was giving me a hexadecimal failure error because of the \u which is now \u.

All of this straightened out allows the asp code to pass an error message to a pretty Javascript box. Hopefully this helps someone else out.

returnValue = returnValue.Replace("\"", "'");
returnValue = returnValue.Replace(@"\", @"\\");
ScriptManager.RegisterStartupScript(Page, this.GetType(), "errorRunExchangeShellMultiCommands", "javascript:showDialogError(\"" + returnValue + "\")", true);

Upvotes: 0

classicSchmosby98
classicSchmosby98

Reputation: 137

There is an opening bracket here with no closing?

"javascript:showDialogError("

Upvotes: 1

James
James

Reputation: 82096

Your actual JS code is fine, the code you are injecting is missing a closing bracket though

"...showDialogError(" + result1 + ")", true)

Upvotes: 2

Related Questions