|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using the && operator in generated JavaScriptI 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> schrieb: I assume this is necessary when using JavaScript in an XHTML page. You >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. 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/> 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 & 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/> 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? 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 & 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/> > > |
|||||||||||||||||||||||