Using the && operator in generated JavaScript

Discussion in 'ASP .Net' started by Nathan Sokalski, Feb 27, 2006.

  1. I have a VB.NET function that I am using in an ASP.NET page. The code
    creates a String, which contains && (the JavaScript Logical AND operator)
    and is used as part of the JavaScript sent to the browser. However, ASP.NET
    is converting this to & even though it is intended to be part of the
    JavaScript. This is causing my JavaScript not to work correctly. How can I
    prevent ASP.NET from doing this substitution? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Feb 27, 2006
    #1
    1. Advertising

  2. "Nathan Sokalski" <> schrieb:
    >I have a VB.NET function that I am using in an ASP.NET page. The code
    >creates a String, which contains && (the JavaScript Logical AND operator)
    >and is used as part of the JavaScript sent to the browser. However, ASP.NET
    >is converting this to &amp; even though it is intended to be part of the
    >JavaScript. This is causing my JavaScript not to work correctly. How can I
    >prevent ASP.NET from doing this substitution? Thanks.


    I assume this is necessary when using JavaScript in an XHTML page. You
    could try to use '<![CDATA[<Your JavaScript code>]]>' to surround the script
    and then use unencoded entities in the script.

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>
     
    Herfried K. Wagner [MVP], Feb 27, 2006
    #2
    1. Advertising

  3. Nathan Sokalski

    Bruce Barker Guest

    IE not being html 4.0 compliant does not support cdata's in script blocks,
    so you have to embed them in javascript comments. (you should also add the
    standard html comment inside the script block)

    <html>
    <body>
    <script>
    <!--
    // <![CDATA[
    if (true && true) document.write("hello world");
    //]]
    -->
    </script>
    </body>
    </html>

    -- bruce (sqlwork.com)


    "Herfried K. Wagner [MVP]" <> wrote in message
    news:ujGDyD$...
    > "Nathan Sokalski" <> schrieb:
    >>I have a VB.NET function that I am using in an ASP.NET page. The code
    >>creates a String, which contains && (the JavaScript Logical AND operator)
    >>and is used as part of the JavaScript sent to the browser. However,
    >>ASP.NET is converting this to &amp; even though it is intended to be part
    >>of the JavaScript. This is causing my JavaScript not to work correctly.
    >>How can I prevent ASP.NET from doing this substitution? Thanks.

    >
    > I assume this is necessary when using JavaScript in an XHTML page. You
    > could try to use '<![CDATA[<Your JavaScript code>]]>' to surround the
    > script and then use unencoded entities in the script.
    >
    > --
    > M S Herfried K. Wagner
    > M V P <URL:http://dotnet.mvps.org/>
    > V B <URL:http://classicvb.org/petition/>
     
    Bruce Barker, Feb 28, 2006
    #3
  4. I am assuming that would work if I were putting the script code between
    SCRIPT tags, but I am using my script in an event handler which I am adding
    using the Attributes.Add() method, such as in the following:

    Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"
    TextBox2.Attributes.Add("onKeyPress", jscode)

    This means that my code must be a String (the second parameter of the Add
    method). I basically just want this part of the code to be output literally,
    without trying to "interpret" anything, which it seems to be doing with the
    &'s (but amazingly not to the > or <). I have never really tried fooling
    aroung with the PreRender event, but putting it in that event make a
    difference?
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Bruce Barker" <> wrote in message
    news:eBwoIx$...
    > IE not being html 4.0 compliant does not support cdata's in script blocks,
    > so you have to embed them in javascript comments. (you should also add the
    > standard html comment inside the script block)
    >
    > <html>
    > <body>
    > <script>
    > <!--
    > // <![CDATA[
    > if (true && true) document.write("hello world");
    > //]]
    > -->
    > </script>
    > </body>
    > </html>
    >
    > -- bruce (sqlwork.com)
    >
    >
    > "Herfried K. Wagner [MVP]" <> wrote in message
    > news:ujGDyD$...
    >> "Nathan Sokalski" <> schrieb:
    >>>I have a VB.NET function that I am using in an ASP.NET page. The code
    >>>creates a String, which contains && (the JavaScript Logical AND operator)
    >>>and is used as part of the JavaScript sent to the browser. However,
    >>>ASP.NET is converting this to &amp; even though it is intended to be part
    >>>of the JavaScript. This is causing my JavaScript not to work correctly.
    >>>How can I prevent ASP.NET from doing this substitution? Thanks.

    >>
    >> I assume this is necessary when using JavaScript in an XHTML page. You
    >> could try to use '<![CDATA[<Your JavaScript code>]]>' to surround the
    >> script and then use unencoded entities in the script.
    >>
    >> --
    >> M S Herfried K. Wagner
    >> M V P <URL:http://dotnet.mvps.org/>
    >> V B <URL:http://classicvb.org/petition/>

    >
    >
     
    Nathan Sokalski, Feb 28, 2006
    #4
    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. Manish_Ganvir
    Replies:
    13
    Views:
    1,634
    Keith Thompson
    Feb 14, 2005
  2. Nathan Sokalski
    Replies:
    4
    Views:
    626
    PJ on Development
    Nov 8, 2007
  3. Jeffrey Walton

    operator= could not be generated

    Jeffrey Walton, Jul 8, 2010, in forum: C++
    Replies:
    6
    Views:
    694
    Jorgen Grahn
    Jul 20, 2010
  4. bintom
    Replies:
    6
    Views:
    333
    Sprechen sie C++
    Mar 10, 2011
  5. Nathan Sokalski
    Replies:
    4
    Views:
    212
    PJ on Development
    Nov 8, 2007
Loading...

Share This Page