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

  • Thread starter Thread starter PJ6
  • Start date Start date
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
 
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)
 
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
 
Back
Top