Get HTML content using Request.Form

5 posts, 0 answers
  1. Erick
    Erick avatar
    12 posts
    Member since:
    Mar 2008

    Posted 26 Sep 2008 Link to this post

    I am generating a custom edit page using an xslt file/transform and in the xslt, I have a RadEditor. Because the RadEditor is in the xslt file, I do not have access to the normal RadEditor methods to get the html content on postback.  Basically, I have to get the content via Request.Form.  Also, the content will be stored as an attribute value in xml, which means it needs to be encoded since I obviously can't store symbols like < & >.

    The content that I get back from Request.Form looks like it has been encoded (ie: < symbol replaced by '%3c') and I can store everything fine in the xml db.  However, when I retrieve the data, I don't have any way of decoding it so it displays correctly in the RadEditor.

    Any ideas on what I can do with the encoded data coming back from the db?
  2. Rumen
    Admin
    Rumen avatar
    12846 posts

    Posted 30 Sep 2008 Link to this post

    Hi Erick,

    We use the code below to encode the the special tags and symbols in HTML content:

    internal class ContentEncoder 
          { 
                static ContentEncoder() 
                { 
                      _characters = new char[] {'%', '<', '>', '!', '"', '#', '$', '&', '\'', '(', ')', ',', ':', 
                                                           ';', '=', '?', '[', '\\', ']', '^', '`', '{', '|', '}', '~', '+'};
                      _characterBytes = Encoding.ASCII.GetBytes(_characters);
                }

                private static char[] _characters;
                private static byte[] _characterBytes;
                public static string Encode(string text)
                {
                      for (int i=0; i<_characterBytes.Length; i++)
                      {
                            text = text.Replace(_characters[i].ToString(), "%" + _characterBytes[i].ToString("x"));
                      }

                      return text;
                }

                public static string Decode(string text)
                {
                      for (int i=_characterBytes.Length - 1; i>=0; i--)
                      {
                            text = text.Replace("%" + _characterBytes[i].ToString("x"), _characters[i].ToString()); 
                      } 
     
                      return text; 
                } 
          } 
     

    Our suggestion is to integrate the code above in your CMS to achieve your scenario.

    Greetings,
    Rumen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Erick
    Erick avatar
    12 posts
    Member since:
    Mar 2008

    Posted 30 Sep 2008 Link to this post

    Thanks for your quick response.  That works perfectly!
  5. christopher willis
    christopher willis avatar
    47 posts
    Member since:
    Sep 2006

    Posted 12 Nov 2008 Link to this post

    This code works well; I am also pulling the editor content from the request.form() collection.

    I'm curious if there is any other server side code that I might be missing when I don't call the edit control content, such as security filters or anything like that?
  6. Rumen
    Admin
    Rumen avatar
    12846 posts

    Posted 12 Nov 2008 Link to this post

    Hi Christopher,

    All editor's filters run on the client. If you want to obtain the editor's content parsed and validated by the filters, you should set the "true" parameter to the editor.get_html() method, e.g.

    editor.get_html(true);


    Best regards,
    Rumen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017