Escape Function in ASP.NET?

Discussion in 'ASP .Net' started by Danny, Jan 15, 2004.

  1. Danny

    Danny Guest

    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.
    Danny, Jan 15, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:%...
    > 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.
    >
    >
    Mark Fitzpatrick, Jan 15, 2004
    #2
    1. Advertising

  3. try Server.HTMLEncode/Server.HTMLDecode (nm)

    --
    Peter O'Reilly
    Peter O'Reilly, Jan 15, 2004
    #3
  4. Danny

    Danny Guest

    Re: try Server.HTMLEncode/Server.HTMLDecode (nm)

    "Peter O'Reilly" <!N!O!.S!P!AM!> wrote in message
    news:...
    > --
    > 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?
    Danny, Jan 15, 2004
    #4
  5. Danny

    bruce barker Guest

    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" <> wrote in message
    news:#...
    > 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.
    >
    >
    bruce barker, Jan 15, 2004
    #5
  6. use Server.HTMLEncode/Server.HTMLDecode

    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
    Peter O'Reilly, Jan 15, 2004
    #6
  7. Danny

    mikeb Guest

    Re: use Server.HTMLEncode/Server.HTMLDecode

    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
    mikeb, Jan 15, 2004
    #7
  8. Danny

    Danny Guest

    Re: use Server.HTMLEncode/Server.HTMLDecode

    Thanks Peter, Mark & Bruce for your suggestions and help.

    - Danny

    "Peter O'Reilly" <!N!O!.S!P!AM!> wrote in message
    news:...
    > 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
    >
    >
    Danny, Jan 15, 2004
    #8
  9. Danny

    mikeb Guest

    Re: try Server.HTMLEncode/Server.HTMLDecode (nm)

    Danny wrote:

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

    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
    mikeb, Jan 15, 2004
    #9
  10. Danny

    Danny Guest

    Re: try Server.HTMLEncode/Server.HTMLDecode (nm)

    That's a neat function. Thanks a lot Mike!

    - Danny

    "mikeb" <> wrote in message
    news:...
    > Danny wrote:
    >
    > > "Peter O'Reilly" <!N!O!.S!P!AM!> wrote in

    message
    > > news:...
    > >
    > >>--
    > >>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=
    >
    > 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
    Danny, Jan 15, 2004
    #10
  11. JScript/JavaScript/ECMAScript

    >
    > 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
    Peter O'Reilly, Jan 15, 2004
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q29vbEtpd2lCbG9rZQ==?=

    URL Escape Character Problem (Bug in ASP.NET??)

    =?Utf-8?B?Q29vbEtpd2lCbG9rZQ==?=, Mar 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    4,675
    Joerg Jooss
    Mar 10, 2005
  2. slomo
    Replies:
    5
    Views:
    1,501
    Duncan Booth
    Dec 2, 2007
  3. Stef Mientki
    Replies:
    11
    Views:
    10,493
    Martin
    Dec 28, 2008
  4. Gerald Britton

    Python 3.2 and html.escape function

    Gerald Britton, Feb 20, 2011, in forum: Python
    Replies:
    5
    Views:
    1,274
    Martin v. Loewis
    Feb 21, 2011
  5. Gerald Britton

    Python 3.2 and html.escape function

    Gerald Britton, Feb 20, 2011, in forum: Python
    Replies:
    0
    Views:
    287
    Gerald Britton
    Feb 20, 2011
Loading...

Share This Page