Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Escaping the & in Attributes.Add()

Reply
Thread Tools

Escaping the & in Attributes.Add()

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      10-02-2007
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
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
Jesse Houwing
Guest
Posts: n/a
 
      10-02-2007
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


 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      10-02-2007
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
(E-Mail Removed)
http://www.nathansokalski.com/

"Jesse Houwing" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>
>



 
Reply With Quote
 
Jesse Houwing
Guest
Posts: n/a
 
      10-02-2007
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
escaping characters Mike P ASP .Net 1 03-29-2006 03:09 PM
Escaping a CrLf in JavaScript George Durzi ASP .Net 0 07-06-2004 05:03 AM
Re: Escaping a URL in XSL/T Teemu Keiski ASP .Net 0 05-13-2004 04:59 PM
Re: Escaping a URL in XSL/T Swanand Mokashi ASP .Net 0 05-13-2004 04:58 PM
Escaping ' in Javascript ? Ben ASP .Net 4 11-10-2003 06:22 PM



Advertisments