Control properties with entity references declared in ASPX get converted to character values

Discussion in 'ASP .Net' started by jesl@lundbeck.com, Feb 13, 2006.

  1. Guest

    Group,

    I have created a User Control with the property "Html" of type string.
    If I declare this control on an ASPX page with the value "<b>This is an
    entity: &lt;</b>" for the property "Html", the ASP.NET parser seems to
    automatically convert the entity reference "&lt;" to it's corresponding
    character value "<".

    For example, if the tagprefix and tagname for the user control is "dn"
    and "test":

    <dn:test Html="<b>This is an entity: &lt;</b>" id="test" runat="server"
    />

    .... this will result in a "Html" value of:

    "<b>This is an entity: <</b>"

    Why does this happen? It is quite annoying because I need to preserve
    the entity reference. Is there any way to preserve entity references in
    properties of type string when these are specified declaratively?

    Thank you!
    , Feb 13, 2006
    #1
    1. Advertising

  2. RE: Control properties with entity references declared in ASPX get con

    Jesl,
    Take a look at the httpserverutility methods. htmlencode and htmldecode.
    These two methods change string to from &lt to < etc.

    http://msdn2.microsoft.com/en-us/library/system.web.httpserverutility_members.aspx


    Good Luck
    DWS






    "" wrote:

    > Group,
    >
    > I have created a User Control with the property "Html" of type string.
    > If I declare this control on an ASPX page with the value "<b>This is an
    > entity: <</b>" for the property "Html", the ASP.NET parser seems to
    > automatically convert the entity reference "<" to it's corresponding
    > character value "<".
    >
    > For example, if the tagprefix and tagname for the user control is "dn"
    > and "test":
    >
    > <dn:test Html="<b>This is an entity: <</b>" id="test" runat="server"
    > />
    >
    > .... this will result in a "Html" value of:
    >
    > "<b>This is an entity: <</b>"
    >
    > Why does this happen? It is quite annoying because I need to preserve
    > the entity reference. Is there any way to preserve entity references in
    > properties of type string when these are specified declaratively?
    >
    > Thank you!
    >
    >
    =?Utf-8?B?RFdT?=, Feb 14, 2006
    #2
    1. Advertising

  3. Guest

    Re: Control properties with entity references declared in ASPX get con

    Thank you, but the problem is that the entity refrences get converted
    even before I can get hold of the string value. Remember: I am reading
    a string property set declaratively in the ASPX. I suspect that the
    problem is that it is the default TypeConverter for strings in the
    ASP.NET framework that is the culprit. Any thoughts on that or how to
    write an alternative TypeConverter that does not touch the string?

    /jesper
    , Feb 15, 2006
    #3
    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. Sammy
    Replies:
    12
    Views:
    1,184
    Richard Tobin
    May 6, 2005
  2. markla
    Replies:
    1
    Views:
    531
    Steven Cheng
    Oct 6, 2008
  3. C Davis
    Replies:
    2
    Views:
    404
    Andy Dingley
    Feb 3, 2009
  4. User Axes Dean Eyed

    Character Entity References & DOM

    User Axes Dean Eyed, Oct 6, 2004, in forum: Javascript
    Replies:
    1
    Views:
    144
    Michael Winter
    Oct 7, 2004
  5. Jim Higson
    Replies:
    3
    Views:
    105
    Jim Higson
    Mar 13, 2005
Loading...

Share This Page