Home All Groups Group Topic Archive Search About

Using the && operator in generated JavaScript

Author
27 Feb 2006 10:42 PM
Nathan Sokalski
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
njsokal***@hotmail.com
http://www.nathansokalski.com/

Author
27 Feb 2006 10:56 PM
Herfried K. Wagner [MVP]
"Nathan Sokalski" <njsokal***@hotmail.com> 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/>
Author
28 Feb 2006 12:16 AM
Bruce Barker
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)


Show quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:ujGDyD$OGHA.1760@TK2MSFTNGP10.phx.gbl...
> "Nathan Sokalski" <njsokal***@hotmail.com> 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/>
Author
28 Feb 2006 1:26 AM
Nathan Sokalski
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
njsokal***@hotmail.com
http://www.nathansokalski.com/

Show quote
"Bruce Barker" <brubar_nospamplease_@safeco.com> wrote in message
news:eBwoIx$OGHA.1532@TK2MSFTNGP12.phx.gbl...
> 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]" <hirf-spam-me-here@gmx.at> wrote in message
> news:ujGDyD$OGHA.1760@TK2MSFTNGP10.phx.gbl...
>> "Nathan Sokalski" <njsokal***@hotmail.com> 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/>
>
>

AddThis Social Bookmark Button