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

RadEditor not respecting the length set using MaxHtmlEditor

4 Answers 78 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Pitamber
Top achievements
Rank 1
Pitamber asked on 03 Nov 2011, 04:56 PM
I have a RadEditor and set its MaxHtmlLength to 50. When I enter more than 50 characters (without any markups) it show an alert box, which is as expected. However, if I add a list, it takes more than 50 characters and does not show an alert message. When I tested the length of the content in server side, it is more than 50.

Here is what I did:
1. Add a RadEditor and a RadButton on the aspx page.
<telerik:RadEditor runat="server" ID="RadEditor1" SkinID="DefaultSetOfTools" Height="515" />
 
<telerik:RadButton ID="btnSave" runat="server"Text="Save">
                <Icon PrimaryIconUrl="/images/usb.png" PrimaryIconLeft="5px" />
            </telerik:RadButton>

2. On Page_Init set the MaxHtmlLength to 50.
this.RadEditor1.MaxHtmlLength = 50;

3. Enter some text and click the button for save.
 Text I used is: 
one two three four five six seven eight nine tens
It has length of 49. If I add another character, I get an alert box though the MaxHtmlLength is 50. 

4. Try some text in a list.
Text I used is:
  • one
  • two thre
 The content for this is, "<ul>\r\n    <li>one</li>\r\n    <li>two thre</li>\r\n</ul>" and the length is 52. I don't get any alert message for this. However, if you try to add one more character, I get an alert message. 

This is how I checked the content and length.
this.RadEditor1.Content.Length; // Get the length of RadEditor content (the value is 52)
this.RadEditor1.Content; // Get the content of the RadEditor ( the value is "<ul>\r\n    <li>one</li>\r\n    <li>two thre</li>\r\n</ul>")

If you increase the MaxHtmlLength to 70 and try with 3 list items, the maximum length allowed is 73. I tested with MaxHtmlLength of 30, 50, and 70 for which the lengths allowed without any alert message are 31, 52, and 73 respectively. 

Note: All this was done using google chrome.

The behavior is different in IE 8. It allows for more than the specified MaxHtmlLength and also appends space at the end of each list.  
Here is how you can reproduce the problem


1. Add the text in list ( I used the same text)
  • one
  • two thre
 Save the data. (For this I have changed the maximum length for the field to 55 in database). It saves without any alert message.
Now, initialize the editor content with the data and try to save again. The same data is not allowed to save and an alert message pops up. I checked and found that space is appended at the end of each list. 

Here is the content in IE8 

"<ul>\r\n    <li>one </li>\r\n    <li>two thre </li>\r\n</ul>"

See the space between the 'e' in one and </li> and also between 'e' in thre and </li> and the length is 54. Try removing 'hr' ( any two characters) it allows to save with the length of 52. It is supposed to show an alert message.

Here is the code for get and set.
get
            {
                return this.RadEditor1.Content.Trim();
            }
  set
            {
                this.RadEditor1.Content = value;
              
            }


I hope this helps you to reproduce the issue.






4 Answers, 1 is accepted

Sort by
0
Pitamber
Top achievements
Rank 1
answered on 03 Nov 2011, 05:04 PM
Sorry, in the title I mean MaxHtmlLength 
0
Rumen
Telerik team
answered on 08 Nov 2011, 11:04 AM
Hello Pitamber,

My suggestion is to disable the built-in IndentHTMLContent indentation filter of RadEditor which adds a lot of spaces to nicely indent the content in HTML mode.

RadEditor1.DisableFilter(EditorFilters.IndentHTMLContent);

You can also strip the \r\n line feeds when obtaining the content from RadEditor
RadEditor1.Content.Replace("\n", "").Replace("\r", "") 

Best regards,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Pitamber
Top achievements
Rank 1
answered on 08 Nov 2011, 03:37 PM
Hi Rumen,
It does not work for me. I am not sure why. Does it work for you or you just thought it might help?

Anyway, thanks.

Pitamber
0
Rumen
Telerik team
answered on 11 Nov 2011, 03:42 PM
Hello Pitamber,

We have received similar reports in the past and the suggestion for disabling the IndentHTMLContent filter helped.

Please, note that there is not a reliable way to compare the content length on the client and  on the server because the content is validated and modified by the browser and the RadEditor's built-in content filters. For example if you load non well formed content in the editor then the editor and the browser will change it even without user interaction and when you save it the content and its length will be different from the initial one.

My suggestion is to disabled all content filters (ContentFilters="None") and trim / strip all line feeds, which should help.

Another option is to implement your own custom length validator and do not set the MaxHtmlLength property. You can see how to implement it in this demo: Validator Support.

Regards,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Editor
Asked by
Pitamber
Top achievements
Rank 1
Answers by
Pitamber
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or