Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Escape Function in ASP.NET?

Reply
Thread Tools

Escape Function in ASP.NET?

 
 
Danny
Guest
Posts: n/a
 
      01-15-2004
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.


 
Reply With Quote
 
 
 
 
Mark Fitzpatrick
Guest
Posts: n/a
 
      01-15-2004
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
 
 
 
Peter O'Reilly
Guest
Posts: n/a
 
      01-15-2004
--
Peter O'Reilly


 
Reply With Quote
 
Danny
Guest
Posts: n/a
 
      01-15-2004
"Peter O'Reilly" <(E-Mail Removed)!N!O!.S!P!AM!> wrote in message
news:(E-Mail Removed)...
> --
> 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?



 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      01-15-2004
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" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
Peter O'Reilly
Guest
Posts: n/a
 
      01-15-2004
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


 
Reply With Quote
 
mikeb
Guest
Posts: n/a
 
      01-15-2004
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
 
Reply With Quote
 
Danny
Guest
Posts: n/a
 
      01-15-2004
Thanks Peter, Mark & Bruce for your suggestions and help.

- Danny

"Peter O'Reilly" <(E-Mail Removed)!N!O!.S!P!AM!> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
mikeb
Guest
Posts: n/a
 
      01-15-2004
Danny wrote:

> "Peter O'Reilly" <(E-Mail Removed)!N!O!.S!P!AM!> wrote in message
> news:(E-Mail Removed)...
>
>>--
>>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
 
Reply With Quote
 
Danny
Guest
Posts: n/a
 
      01-15-2004
That's a neat function. Thanks a lot Mike!

- Danny

"mikeb" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Danny wrote:
>
> > "Peter O'Reilly" <(E-Mail Removed)!N!O!.S!P!AM!> wrote in

message
> > news:(E-Mail Removed)...
> >
> >>--
> >>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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python 3.2 and html.escape function Gerald Britton Python 5 02-21-2011 11:59 PM
Python 3.2 and html.escape function Gerald Britton Python 0 02-20-2011 05:51 PM
Is there a function to remove escape characters from a string ? Stef Mientki Python 11 12-28-2008 02:19 AM
How to read strings cantaining escape character from a file and useit as escape sequences? slomo Python 5 12-02-2007 11:39 AM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM



Advertisments