Difficulty with LinkButton.Attribute[] usage

Discussion in 'ASP .Net Web Controls' started by Guest, Apr 20, 2004.

  1. Guest

    Guest Guest

    Hello,

    I am trying to create an anchor tag on a page that look like this:

    <a id="some_id" onSomeAction="this.href='page.aspx?a=1&b=2'">some_text</a>

    I tried to accomplish this using System.Web.UI.WebControls.LinkButton object
    and using the following statement:

    linkbutton.Attributes ["onSomeAction"] = "this.href='page.aspx?a=1&b=2'";

    When run, the '&' character gets translated to '&amp;' . As a result, the
    output on the page looks like this:

    <a id="some_id"
    onSomeAction="this.href='page.aspx?a=1&amp;b=2'">some_text</a>


    Would anyone be able to tell me how to disable the translation of the '&'
    character.

    Thanks
     
    Guest, Apr 20, 2004
    #1
    1. Advertising

  2. > I am trying to create an anchor tag on a page that look like this:
    >
    > <a id="some_id" onSomeAction="this.href='page.aspx?a=1&b=2'">some_text</a>
    >
    > I tried to accomplish this using System.Web.UI.WebControls.LinkButton object
    > and using the following statement:
    >
    > linkbutton.Attributes ["onSomeAction"] = "this.href='page.aspx?a=1&b=2'";
    >
    > When run, the '&' character gets translated to '&amp;' . As a result, the
    > output on the page looks like this:
    >
    > <a id="some_id"
    > onSomeAction="this.href='page.aspx?a=1&amp;b=2'">some_text</a>


    I used Reflector to look at the code for the AttributeCollection's
    Render() method. Essentially, it loops through the added attributes,
    and does a writer.WriteAttribute(...) call, passing in the key and value
    of the attribute, where writer is an HtmlTextWriter instance.

    Now, here's the rub. The HtmlTextWriter's WriteAttribute() method takes
    in as a third parameter a Boolean indicating whether or not the HTML
    passed in should be HTML encoded. The AttributeCollection's Render()
    method, unfortunately, passes in a hard-coded value of true. :-(

    There may be an elegant workaround, but I can't think of one off the top
    of my head. Sorry!

    --

    Scott Mitchell

    http://www.4GuysFromRolla.com
    http://www.ASPFAQs.com
    http://www.ASPMessageboard.com

    * When you think ASP, think 4GuysFromRolla.com!
     
    Scott Mitchell [MVP], Apr 21, 2004
    #2
    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. Sathyaish
    Replies:
    3
    Views:
    3,121
    Sathyaish
    Sep 8, 2005
  2. metfan
    Replies:
    2
    Views:
    4,855
    Robert Olofsson
    Oct 21, 2003
  3. Colin J. Williams

    Webchecker Usage - a problem with local usage

    Colin J. Williams, Feb 25, 2004, in forum: Python
    Replies:
    1
    Views:
    545
    Colin J. Williams
    Feb 26, 2004
  4. =?Utf-8?B?SmVmZkRvdE5ldA==?=

    Difficulty disabling the read-only attribute on an ASP.net working

    =?Utf-8?B?SmVmZkRvdE5ldA==?=, Mar 22, 2007, in forum: ASP .Net
    Replies:
    7
    Views:
    542
    Walter Wang [MSFT]
    Mar 28, 2007
  5. Sathyaish

    Linkbutton does not look like a linkbutton

    Sathyaish, Sep 8, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    195
    Sathyaish
    Sep 8, 2005
Loading...

Share This Page