Issue with Control.Attributes Property when adding Javascript

Discussion in 'ASP .Net' started by ChrisMiddle10@gmail.com, Oct 12, 2006.

  1. Guest

    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!
    , Oct 12, 2006
    #1
    1. Advertising

  2. Guest

    Are there alternate methods for comparisons?

    For example:
    bool greaterThan( x, y );
    bool lessThanEqualTo( x, y );
    , Oct 12, 2006
    #2
    1. Advertising

  3. apathetic Guest

    wrote:
    > 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
    apathetic, Oct 12, 2006
    #3
  4. apathetic Guest

    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
    apathetic, Oct 12, 2006
    #4
  5. Guest

    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?
    , Oct 12, 2006
    #5
  6. apathetic Guest

    wrote:
    > 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
    apathetic, Oct 12, 2006
    #6
  7. Guest

    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 )
    {

    }
    , Oct 12, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski
    Replies:
    8
    Views:
    4,592
    Raymond
    Mar 1, 2006
  2. Replies:
    0
    Views:
    337
  3. Nathan Sokalski
    Replies:
    0
    Views:
    386
    Nathan Sokalski
    Jan 8, 2008
  4. Zarko Gajic

    Custom Attributes (AttributeTargets.Property) and Property Type

    Zarko Gajic, Apr 7, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    426
    Zarko Gajic
    Apr 7, 2005
  5. Nathan Sokalski

    Requirements for using Control & Property Attributes in ASP.NET

    Nathan Sokalski, Jan 8, 2008, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    799
    Nathan Sokalski
    Jan 8, 2008
Loading...

Share This Page