473,377 Members | 1,119 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,377 software developers and data experts.

Escape Function in ASP.NET?

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.
Nov 18 '05 #1
10 8311
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

"Danny" <da******@NoSPAMmyrealbox.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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.

Nov 18 '05 #2
--
Peter O'Reilly
Nov 18 '05 #3
"Peter O'Reilly" <Pe***********@timeinc.com!N!O!.S!P!AM!> wrote in message
news:OM**************@TK2MSFTNGP09.phx.gbl...
--
Peter O'Reilly


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?

Nov 18 '05 #4
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)

"Danny" <da******@NoSPAMmyrealbox.com> wrote in message
news:#f**************@TK2MSFTNGP11.phx.gbl...
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.

Nov 18 '05 #5
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 O'Reilly
Nov 18 '05 #6
Peter O'Reilly wrote:
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.

--
mikeb
Nov 18 '05 #7
Thanks Peter, Mark & Bruce for your suggestions and help.

- Danny

"Peter O'Reilly" <Pe***********@timeinc.com!N!O!.S!P!AM!> wrote in message
news:e0**************@TK2MSFTNGP09.phx.gbl...
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 O'Reilly

Nov 18 '05 #8
Danny wrote:
"Peter O'Reilly" <Pe***********@timeinc.com!N!O!.S!P!AM!> wrote in message
news:OM**************@TK2MSFTNGP09.phx.gbl...
--
Peter O'Reilly

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/groups?selm...TNGP10.phx.gbl

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

--
mikeb
Nov 18 '05 #9
That's a neat function. Thanks a lot Mike!

- Danny

"mikeb" <ma************@mailnull.com> wrote in message
news:uR**************@TK2MSFTNGP10.phx.gbl...
Danny wrote:
"Peter O'Reilly" <Pe***********@timeinc.com!N!O!.S!P!AM!> wrote in message news:OM**************@TK2MSFTNGP09.phx.gbl...
--
Peter O'Reilly

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/groups?selm...TNGP10.phx.gbl
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).

--
mikeb

Nov 18 '05 #10
>
JScript.NET is included in the .NET Framework, and has been since day
one (I believe).

However, VS.NET does not support it.

--
mikeb


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.

--
Peter O'Reilly
Nov 18 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Richard Trahan | last post by:
I need a javascript function to hex-encode a plus sign so I can pass the plus sign as an argument in a GET request. escape() and encodeURI() don't do it (and probably shouldn't, because '+' is a...
2
by: Diarmaid McGleenan | last post by:
I have a javascript function called ShowActiveLink to which I pass a full <a href="blah.htm" onClick="javascript:newWindow('quotedStuff');"> link. (See below.) --------------- <script...
3
by: robburne | last post by:
Can anyone help with my javascript code please? I have a button which when pressed calls a function named 'popjack' which pops up a new browser window. The function is called with a paramter...
2
by: Pavils Jurjans | last post by:
Hello, I am looking fow C# equivalent of JavaScripts escape() and unescape() functions. I need to use C# function at the server side and then be able to use the opposite at the client side. ...
2
by: genc_ ymeri at hotmail dot com | last post by:
Hi , Does .Net have any method/function that escape charcters while writing a XML file ???? Thank you in advance.
1
by: chuck | last post by:
Hi, I have a php function creating links from a products mysql database. some of the descriptions have characters that I need to escape but whatever i do, javascript doesn't like them. for...
131
by: Lawrence D'Oliveiro | last post by:
The "escape" function in the "cgi" module escapes characters with special meanings in HTML. The ones that need escaping are '<', '&' and '"'. However, cgi.escape only escapes the quote character if...
1
by: christopher.tokar | last post by:
Hello, I was wondering if there are any proper, robust libraries or functions/methods that I don't know of that will escape all the problematic characters such as single quotes and tabs. I find...
3
by: qilin | last post by:
I am trying to save a big text string into MySQL, but I guess i need escape the string firstly, anybody knows any escape function in c for that? or any other suggests ?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.