HtmlTextWriter Re-encoding my strings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?cndvb2RydWY=?=

    #1

    HtmlTextWriter Re-encoding my strings

    Hello All,

    I am using an HtmlTextWriter to writer out some html. Prior to sending the
    content to the text writer, HttpUtility.Htm lEncode the string. However, doing
    so results in a string where "&" become "&amp;" and "<" becomes "<".

    This is a problem because I am trying to actually write out html. Does
    anyone know how I can solve this problem.

    For example

    HttpUtility.Htm lEncode("&Attri butes");

    gives

    "&&Attribut es"

    after being written out by the HtmlTextWriter. The initial encoding results
    in "&Attribute s". I just want it to be written out as "&Attribute s".
    Decoding does something even weirder :)

    Thanks for your help.
  • George Ter-Saakov

    #2
    Re: HtmlTextWriter Re-encoding my strings

    Why do you use HtpUtility.Html Encode then??
    Just do not use it when you outputing HTML


    George


    "rwoodruf" <rwoodruf@discu ssions.microsof t.comwrote in message
    news:D584E6E2-C011-43B4-9F1A-311EBFD03355@mi crosoft.com...
    Hello All,
    >
    I am using an HtmlTextWriter to writer out some html. Prior to sending the
    content to the text writer, HttpUtility.Htm lEncode the string. However,
    doing
    so results in a string where "&" become "&amp;" and "<" becomes "<".
    >
    This is a problem because I am trying to actually write out html. Does
    anyone know how I can solve this problem.
    >
    For example
    >
    HttpUtility.Htm lEncode("&Attri butes");
    >
    gives
    >
    "&&Attribut es"
    >
    after being written out by the HtmlTextWriter. The initial encoding
    results
    in "&Attribute s". I just want it to be written out as "&Attribute s".
    Decoding does something even weirder :)
    >
    Thanks for your help.

    Comment

    • =?Utf-8?B?cndvb2RydWY=?=

      #3
      Re: HtmlTextWriter Re-encoding my strings

      It seems that the HtmlTextWriter is automatically encoding the strings
      because without the HttpUtility.Htm lEncode, the following:

      "&Attribute s"

      becomes

      "&amp;Attribute s"

      So, any help is appreciated. It looks like the HtmlTextWriter automatically
      Html Encode's all strings.

      -- Rodney

      "George Ter-Saakov" wrote:
      Why do you use HtpUtility.Html Encode then??
      Just do not use it when you outputing HTML
      >
      >
      George
      >
      >
      "rwoodruf" <rwoodruf@discu ssions.microsof t.comwrote in message
      news:D584E6E2-C011-43B4-9F1A-311EBFD03355@mi crosoft.com...
      Hello All,

      I am using an HtmlTextWriter to writer out some html. Prior to sending the
      content to the text writer, HttpUtility.Htm lEncode the string. However,
      doing
      so results in a string where "&" become "&" and "<" becomes "<".

      This is a problem because I am trying to actually write out html. Does
      anyone know how I can solve this problem.

      For example

      HttpUtility.Htm lEncode("&Attri butes");

      gives

      "&&Attribut es"

      after being written out by the HtmlTextWriter. The initial encoding
      results
      in "&Attribute s". I just want it to be written out as "&Attribute s".
      Decoding does something even weirder :)

      Thanks for your help.
      >
      >
      >

      Comment

      • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

        #4
        RE: HtmlTextWriter Re-encoding my strings

        "&"'s are only legal inside a CDATA, thats why they are automatically encoded
        by the text writer.

        -- bruce (sqlwork.com)


        "rwoodruf" wrote:
        Hello All,
        >
        I am using an HtmlTextWriter to writer out some html. Prior to sending the
        content to the text writer, HttpUtility.Htm lEncode the string. However, doing
        so results in a string where "&" become "&" and "<" becomes "<".
        >
        This is a problem because I am trying to actually write out html. Does
        anyone know how I can solve this problem.
        >
        For example
        >
        HttpUtility.Htm lEncode("&Attri butes");
        >
        gives
        >
        "&&Attribut es"
        >
        after being written out by the HtmlTextWriter. The initial encoding results
        in "&Attribute s". I just want it to be written out as "&Attribute s".
        Decoding does something even weirder :)
        >
        Thanks for your help.

        Comment

        Working...