Escape Function in ASP.NET?

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.
 
M

Mark Fitzpatrick

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
 
D

Danny

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

bruce barker

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)
 
P

Peter O'Reilly

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.
 
M

mikeb

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.
 
M

mikeb

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).
 
P

Peter O'Reilly

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.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top