473,856 Members | 1,750 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 3244
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
1963
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
2466
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
1381
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
2821
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
1726
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
9904
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
9758
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11051
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...
1
10773
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
10378
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...
0
7087
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
5756
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...
0
5956
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4571
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

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.