This is a migrated thread and some comments may be shown as answers.

Get HTML content using Request.Form

5 Answers 151 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Erick
Top achievements
Rank 1
Erick asked on 26 Sep 2008, 06:38 PM
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?

5 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 30 Sep 2008, 09:11 AM
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.
0
Erick
Top achievements
Rank 1
answered on 30 Sep 2008, 06:37 PM
Thanks for your quick response.  That works perfectly!
0
christopher willis
Top achievements
Rank 1
answered on 12 Nov 2008, 05:03 PM
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?
0
Rumen
Telerik team
answered on 12 Nov 2008, 06:12 PM
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.
0
Rajesh
Top achievements
Rank 1
answered on 12 Jan 2018, 12:03 PM
Thanks. It is working for me.code is well work. thanks once again
Tags
Editor
Asked by
Erick
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Erick
Top achievements
Rank 1
christopher willis
Top achievements
Rank 1
Rajesh
Top achievements
Rank 1
Share this question
or