views:

69

answers:

2
if (confirm('<%=Ns1.Ns2.MyClass.GetResourceText("DeleteConfirmationMessage")%>')) { /* something to do...*/ }

I have a jQuery expression as above. But the return value of GetResourceText method is a very long string. So my page renders the function like below:

if (confirm('
                Are you sure lablabla? If you delete this lablabla...
                lablabla...
            ')) {

Because of this my jQuery functions do not work. Is there a symbol for jQuery like @ that we use in C#?

A: 

\. Just place it at the end of the line:

var str = "this \
is on more \
than one line \
and is valid.";
alert(str); // alerts "this is on more than one line and is valid."
David Murdoch
This will destroy the multi-line formatting.
Hans Kesting
Did he say he wants multiple-line formatting? or wait. Couldn't the OP just add back in `\n` before the ` \\ `? Obviously they know about new-lines already or they wouldn't be having this problem in the first palce.
David Murdoch
+2  A: 

Note: jQuery is not a special language, that would be javascript.

You will have to pass this string though an extra method that replaces all newlines with the string "\n". Take care when doing this from C#: you need the literal string "\n" so you will need escaping, either @"\n" or "\\n".

You also will need to watch out for quotes: a message like "call O'Brien" will fail with a javascript error. Replace that with "'".

Hans Kesting