Issue with Control.Attributes Property when adding Javascript

C

ChrisMiddle10

Sorry to bother everyone with this question, but the answer to this the
question is difficult to search for. I want to add javascript to an
HtmlInputButton control attribute. A portion of the javascript goes
something like this:

if( x < y && x != y )
{
// do something
}

It is rendered as follows:

if( x &lt; y &amp;&amp; x != y )
{
// do something
}

How do I preserve the literal "<" and "&"?

Thanks a lot!
 
C

ChrisMiddle10

Are there alternate methods for comparisons?

For example:
bool greaterThan( x, y );
bool lessThanEqualTo( x, y );
 
A

apathetic

I want to add javascript to an HtmlInputButton control attribute ...
How do I preserve the literal "<" and "&"?

You don't. When you call Attributes.Add(), ASP.NET automatically
converts them to their HTML entity references, which is correct. Are
you finding that this method doesn't work correctly?

Tim
 
A

apathetic

To clarify, the output you are getting is the correct way to output
those characters in an attribute. Why do you need to change this
behaviour? Do you find that the script fails to execute?

Tim
 
C

ChrisMiddle10

Well I suppose the method is working "correctly", but from what I can
tell it is limiting my ability to insert javascript into the attribute
value. I need to do the comparison somehow. I'd prefer to keep the
javascript in that particular button's element.

Can you think of a good work-around? Is the Render method going to be
my best bet for getting the results I want?
 
A

apathetic

I want to add javascript to an HtmlInputButton control attribute ...
How do I preserve the literal "<" and "&"?

You don't. When you call Attributes.Add(), ASP.NET automatically
converts them to their HTML entity references, which is correct. Are
you finding that this method doesn't work correctly?

Tim
 
C

ChrisMiddle10

In response to your prior post for clarification:

Yes, the script does not execute due to a syntax error. When I view the
source I see something like:

if( x &lt; y &amp;&amp; y &gt; x )
{

}

The above is definitely not correct syntax. What I need is:

if( x < y && y > x )
{

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top