can ASP.NET properly parse a string to pass to JavaScript?

P

PJ6

I can probably code this up manually myself but I'd prefer to use a built-in
method that I'm sure exists... I have a message box client-side control
(thanks, Steve Orr) that uses the JavaScript alert() method to pass text to
a user in a dialogue box. Often I have messages containing text that
JavaScript doesn't like, like single quote characters. Does ASP.NET have a
method to parse text for JavaScript? Server.HTMLEncode doesn't seem to do
the trick.

TIA,
Paul
 
B

Bruce Barker

yes, but its private, so you can not call it. here is a simple one:

public static string JscriptQuote(string s)
{
s = s.Replace("'", "\\'");
s = s.Replace("\n", "\\n");
s = s.Replace("\r", "");
return "'" + s + "'";
}

-- bruce (sqlwork.com)
 
P

PJ6

Private? They bent over backwards to give us methods for everything else.
That just doesn't make any sense to me.

Oh well. Thanks for the info.

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top