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

How to prevent RadEditor from adding non-breaking spaces to the end of line?

3 Answers 310 Views
Editor
This is a migrated thread and some comments may be shown as answers.
jgill
Top achievements
Rank 1
jgill asked on 11 Sep 2010, 07:35 AM
Hello,
I am having an issue where I have a multi-line RadEditor and when the user enters any text into the editor then submits that content to be saved to the database, RadEditor is adding a non-breaking space (see attachment).  I wanted to know how this can be prevented in the RadEditor through configuration instead of lots of find and replaces each time a RadEditor is used.

In SQL Server this is CHAR(13)+CHAR(10) in UTF-8 encoding on Regex.Replace(Input, "\u00A0", "").

<telerik:RadEditor ID="RadEditor1" runat="server" AllowScripts="True">
<Content>
</Content>
                    </telerik:RadEditor>

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 15 Sep 2010, 11:55 AM
Hi jgill,

RadEditor is adding \r\n symbols to the content for readability. Due to them when the editor's content is displayed in Html mode or in the Database it will be readable.

If you do not want these line-feed and line breaks in the produced content you can use the Trim method of the Content server property:

RadEditor1.Content = RadEditor1.Content.Trim(); .

Another approach is to replace the line-feed and new line with empty string using the Replace method

RadEditor1.Content = RadEditor1.Content.Replace("\r", "").Replace("\n", "");

Best regards,
Rumen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
AT Murugan
Top achievements
Rank 1
answered on 31 Dec 2012, 10:18 AM
Hi,

I am also facing the same issue with the GridTextBoxColumnEditor, my data is saved with the spaces,

Please help me in this regard,

Regards,
Ananda
0
Rumen
Telerik team
answered on 02 Jan 2013, 02:35 PM
Hi,

You can get reference to RadEditor using the code similar to the one below:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
   if (e.Item is GridEditableItem && e.Item.IsInEditMode)
   {
     GridDataItem dataItem = e.Item as GridDataItem;
     RadEditor Editor = (RadEditor)dataItem["Note"].Controls[0];//"Note" is the current row in which the editor resides
     Editor.Content = Editor.Content.Replace("\r", "").Replace("\n", "");
  }
}


Here is additional way to get reference to RadEditor in RadGrid:

protected void notes_grid_ItemDataBound(object sender, GridItemEventArgs e)
{
   // insert mode
      if (e.Item is GridDataInsertItem && e.Item.OwnerTableView.IsItemInserted)
  {
       GridDataInsertItem insertItem = (GridDataInsertItem)e.Item;
     RadEditor Editor = (RadEditor)insertItem["Note"].Controls[0];
        Editor.Content = Editor.Content.Replace("\r", "").Replace("\n", "");
      }
   // edit mode
  if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))
  {
     GridEditableItem editItem = (GridEditableItem)e.Item;
            RadEditor Editor = (RadEditor)editItem["Note"].Controls[0];
        Editor.Content = Editor.Content.Replace("\r", "").Replace("\n", "");
    }
}

If this does not help, provide a simple working demo that demonstrates the problem.



Kind 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
jgill
Top achievements
Rank 1
Answers by
Rumen
Telerik team
AT Murugan
Top achievements
Rank 1
Share this question
or