473,686 Members | 3,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Escaping the & in Attributes.Add( )

I am adding an onmouseover attribute using the Attributes.Add( ) method, and
the String I am using for the value contains the & character. However, when
rendered the & is converted to the HTML representation of & which causes
my JavaScript not to work. What can I do to prevent the Add() method from
modifying my value? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Oct 2 '07 #1
3 3231
Hello Nathan,
I am adding an onmouseover attribute using the Attributes.Add( )
method, and the String I am using for the value contains the &
character. However, when rendered the & is converted to the HTML
representation of & which causes my JavaScript not to work. What
can I do to prevent the Add() method from modifying my value? Thanks.
Any attribute must escape the HTML special characters. An onCLick as well.
Are you sure this is causing the error?

--
Jesse Houwing
jesse.houwing at sogeti.nl
Oct 2 '07 #2
Yes, I am sure because I create the value by assigning a value to a String
variable, and then using that variable in the Attributes.Add( ) method. For
example:

Dim onmouseover as String= "my javascript code" 'This contains &'s in my
actual code
mycontrol.Attri butes.Add("onmo useover",onmous eover)

When I used this technique and ran a Debug session, the String onmouseover
looked exactly as I wanted, but the rendered code had replaced the &'s with
& which is what I am trying to avoid. Any ideas? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Jesse Houwing" <je***********@ newsgroup.nospa mwrote in message
news:21******** *************** ***@news.micros oft.com...
Hello Nathan,
>I am adding an onmouseover attribute using the Attributes.Add( )
method, and the String I am using for the value contains the &
character. However, when rendered the & is converted to the HTML
representati on of &amp; which causes my JavaScript not to work. What
can I do to prevent the Add() method from modifying my value? Thanks.

Any attribute must escape the HTML special characters. An onCLick as well.
Are you sure this is causing the error?

--
Jesse Houwing
jesse.houwing at sogeti.nl


Oct 2 '07 #3
Hello Nathan,
Yes, I am sure because I create the value by assigning a value to a
String variable, and then using that variable in the Attributes.Add( )
method. For example:

Dim onmouseover as String= "my javascript code" 'This contains &'s in
my
actual code
mycontrol.Attri butes.Add("onmo useover",onmous eover)
When I used this technique and ran a Debug session, the String
onmouseover looked exactly as I wanted, but the rendered code had
replaced the &'s with &amp; which is what I am trying to avoid. Any
ideas? Thanks.
There are no idea's. The spec says that every attribute must be encoded using
html encoding. That includes the &. The javascript perser should work.

If you run it in Firefox, what is the message on the javascript console when
you click the html element in question (firefox is usually a bit mor eoncise
in it's error messages). There must be somethign else wrong here.

I tested the code below:

<html>
<body>
<form>
<input type="button" onclick="alert( true &amp;&amp; true);" value="test">
</form>
</body>
</html>

And it works in both Internet Explorer and Firefox (it should say true in
the alert when you click the button).

Jesse

"Jesse Houwing" <je***********@ newsgroup.nospa mwrote in message
news:21******** *************** ***@news.micros oft.com...
>Hello Nathan,
>>I am adding an onmouseover attribute using the Attributes.Add( )
method, and the String I am using for the value contains the &
character. However, when rendered the & is converted to the HTML
representatio n of &amp; which causes my JavaScript not to work. What
can I do to prevent the Add() method from modifying my value?
Thanks.
Any attribute must escape the HTML special characters. An onCLick as
well. Are you sure this is causing the error?

--
Jesse Houwing
jesse.houwin g at sogeti.nl
--
Jesse Houwing
jesse.houwing at sogeti.nl
Oct 2 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1955
by: Paul Hatcher | last post by:
Hi I'm transforming some XML to HTML but the via XslTransform and a StreamWriter, but I can't get it to obey <xsl:text> escaping rules. I have a statement <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text> but I get &amp;nbsp; in the output rather than &nbsp;
4
2455
by: Prodip Saha | last post by:
Dear ASP.NET Gurus, I have a TextBox control with AutoPostBack set to true to execute the server scripts. I also, added some client script for validation.What I want is--execute the client script and if the cleint script returns true only then I want to execute the server scripts. Am I asking too much or is it achievable? Please don't give me an answer like --just validate on the server side... Some Background:- I have deligated an...
3
1354
by: Nathan Sokalski | last post by:
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. -- Nathan Sokalski...
8
2806
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);" TextBox2.Attributes.Add("onKeyPress", jscode) You will notice that jscode contains the JavaScript Logical And operator (&&). However, ASP.NET renders this as &amp;&amp; in the code that is
11
1713
by: gisleyt | last post by:
I need to escape e.g. & within an attribute, as in: <foo bar="+$"/> Since this is a regular expression and will not be validated as a normal xml file, i cannot use &amp; for &. CDATA does not seem to work in an attribute either. Any suggestions on how I can get around this? -Gisle-
0
8588
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9061
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8946
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8779
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8783
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6448
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4320
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
1943
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.