xkcd
xkcd

Reputation: 2590

@ symbol for strings in jQuery

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

Upvotes: 1

Views: 209

Answers (2)

Hans Kesting
Hans Kesting

Reputation: 39274

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 "'".

Upvotes: 3

David Murdoch
David Murdoch

Reputation: 89322

\. 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."

Upvotes: -1

Related Questions