473,513 Members | 2,688 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********@hotmail.com
http://www.nathansokalski.com/
Oct 2 '07 #1
3 3218
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.Attributes.Add("onmouseover",onmouseover )

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********@hotmail.com
http://www.nathansokalski.com/

"Jesse Houwing" <je***********@newsgroup.nospamwrote in message
news:21**************************@news.microsoft.c om...
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 &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.Attributes.Add("onmouseover",onmouseover )
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.nospamwrote in message
news:21**************************@news.microsoft.c om...
>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 &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
--
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
1949
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
2445
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...
3
1333
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...
8
2785
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...
11
1699
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
7397
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. ...
0
7563
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...
1
7125
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...
0
5703
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5102
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...
0
3239
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
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...

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.