ContentFilters=None not working as expected

2 posts, 0 answers
  1. Warren
    Warren avatar
    7 posts
    Member since:
    Jul 2006

    Posted 08 May 2013 Link to this post


    Given this C# code:
            HtmlContentEditor1.Content = @"<html><body>
    <img height=""0"" width=""0"">
    <a href="""" style=""color: #9a9a9a;"">Telerik</a><br>
    and this in the .aspx file:
    <telerik:RadEditor runat="server" ID="HtmlContentEditor1"
        EditModes="Html" Width="600" ContentFilters="None" />

    we are seeing the HTML content get rewritten as:
    <img width="0" height="0">
    <a style="color: rgb(154, 154, 154);" href="">Telerik</a><br>

    and when the ContentFilters="None" property is removed altogether, the HTML content gets rewritten as:
            <img alt="" width="0" height="0" />
            <a href="" style="color: #9a9a9a;">Telerik</a><br />

    This is pretty unusual behaviour -- in the first case it reordered attributes and rewrote inline styles.... and in the second case it reordered attributes and added one in the <img> tag, but left the <a> tag alone.  

    The HTML rewriting only seems to happen when initializing the control after setting the Content property. If I paste content into the HTML tab, then post the control back to the server, the content is unaltered.

    We'd like to be able to use RadEditor for a project but it is critical that the editor not change the HTML content at all.  Is this possible?

    I can provide a sample project but it's larger than the 2MB upload limit due to it including the controls DLL itself.  Controls version is 2013.1.319.40.

    Any insight into this issue would be appreciated, thanks.

  2. Joana
    Joana avatar
    205 posts

    Posted 13 May 2013 Link to this post

    Hello Warren,

    The issue you have described is encountered because of browser behavior. ConvertXHTML filter handles this behavior and that's why you don't experience the issue when you remove ContentFilters="None" from your code. You can find more information about the Built-In content filters in this article.

    I suggest that you use the following code that shows an example of creating a custom filter to replace the RGB value with HEX value.

        function OnClientLoad(editor, args) {
            var filter = new Filter();
        Filter = function () {
        Filter.prototype =
                getHtmlContent: function (content) {
                    return this._removeHtmlTags(content);
                _removeHtmlTags: function (initContent) {
                    var cleanContent;
                    cleanContent = initContent.replace(/rgb *\( *\d+ *, *\d+ *, *\d+ *\)/gi, function (match, offset, fullText) {
                        return Telerik.Web.UI.Editor.Utils._rgbToHex(match);
                    return cleanContent
        Filter.registerClass('Filter', Telerik.Web.UI.Editor.Filter);

    I hope you find this information helpful.

    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.
Back to Top