472,110 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Using the && operator in generated JavaScript

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
nj********@hotmail.com
http://www.nathansokalski.com/
Feb 27 '06 #1
3 1207
"Nathan Sokalski" <nj********@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/>

Feb 27 '06 #2
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]" <hi***************@gmx.at> wrote in message
news:uj**************@TK2MSFTNGP10.phx.gbl...
"Nathan Sokalski" <nj********@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/>

Feb 28 '06 #3
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
nj********@hotmail.com
http://www.nathansokalski.com/

"Bruce Barker" <br******************@safeco.com> wrote in message
news:eB**************@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]" <hi***************@gmx.at> wrote in message
news:uj**************@TK2MSFTNGP10.phx.gbl...
"Nathan Sokalski" <nj********@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/>


Feb 28 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Sergio Otoya | last post: by
2 posts views Thread by Dean | last post: by
12 posts views Thread by daniel kaplan | last post: by
11 posts views Thread by srinivas | last post: by
6 posts views Thread by prash.marne | last post: by
2 posts views Thread by Bharath | last post: by
reply views Thread by leo001 | last post: by

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.