Escape Function in ASP.NET?

  • Thread starter Thread starter Danny
  • Start date Start date
D

Danny

In the classic asp, I can use escape built-in function (server side
function) like this:

<script language=javascript>
var myContent = unescape(<%=escape(strContent)%>)
</script>

How do I do that in asp.net? Seems like escape server side function is no
longer provided in asp.net, or am I missing something here?

Thanks in advance,

- Danny

Ps. Don't suggest me to run Javascript escape function, since I need to
escape this on the server side.
 
Actually, this wasn't an ASP feature and was limited to the VBScript
language. The System.Text namespace offers a number of functions for
transforming strings into ASCII and Unicode.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
Thanks Peter, but Server.HTMLEncode/Decode can't help me.
What I want actually send the data in "escape" format to Javascript
function, and Javascript will "unescape" it.
Like what I explained in my first post:

<script language=javascript>
var myContent = unescape(<%=escape(strContent)%>)
</script>

sContent can contain linebreak, apostrophy, quote, etc. That's why I want to
change the data before I send it to Javascript to avoid script error when
Javascript tries to load it.

Any ideas?
 
use Server.URLEncode(s). also escape is obsolete and you should use
decodeURI..

<script language=javascript>
var myContent = decodeURI(<%=Server.URLEncode(strContent)%>);
</script>

-- bruce (sqlwork.com)
 
ASP.NET's HttpServerUtility.HtmlDecode is equivalent to JavaScript's
unescape() global function. Likewise the same is true for their compliment,
HttpServerUtility.HtmlEncode and escape(). Give it a try..

Additional thread tidbit drift..
decodeURI() and encodeURI() now exist, which makes unescape() and escape()
functions deprecated. I'd still use the latter (and use the former
judiciously) as theses are JavaScript version 1.5 global functions which
only work with recent browser releases.

The JavaScript language may also be used for server scripting, e.g. using
Netscape enterprise software products. Since you are posting this message
on an ASP.NET newsgroup - there's no CLR compliant JavaScript language
vendor/product that I'm aware of.
 
Peter said:
ASP.NET's HttpServerUtility.HtmlDecode is equivalent to JavaScript's
unescape() global function. Likewise the same is true for their compliment,
HttpServerUtility.HtmlEncode and escape(). Give it a try..

Additional thread tidbit drift..
decodeURI() and encodeURI() now exist, which makes unescape() and escape()
functions deprecated. I'd still use the latter (and use the former
judiciously) as theses are JavaScript version 1.5 global functions which
only work with recent browser releases.

The JavaScript language may also be used for server scripting, e.g. using
Netscape enterprise software products. Since you are posting this message
on an ASP.NET newsgroup - there's no CLR compliant JavaScript language
vendor/product that I'm aware of.

JScript.NET is included in the .NET Framework, and has been since day
one (I believe).

However, VS.NET does not support it.
 
Danny said:
Thanks Peter, but Server.HTMLEncode/Decode can't help me.
What I want actually send the data in "escape" format to Javascript
function, and Javascript will "unescape" it.
Like what I explained in my first post:

<script language=javascript>
var myContent = unescape(<%=escape(strContent)%>)
</script>

sContent can contain linebreak, apostrophy, quote, etc. That's why I want to
change the data before I send it to Javascript to avoid script error when
Javascript tries to load it.

Any ideas?

Take a look at this posting:


http://groups.google.com/[email protected]

It has a small custom function that does most of what you want (you'll
probably have to add something to escape the linefeeds and possibly
other chars).
 
JScript.NET is included in the .NET Framework, and has been since day
one (I believe).

However, VS.NET does not support it.

Mike you are absolutely correct. JScript/JScript.NET is Microsoft's
specific implemenation of ECMA-262 (ECMAScript); JavaScript is Netscape's
flavor of ECMA. A bit of a brain-fade before on my part with the names.
 
Back
Top