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

4 posts, 0 answers
  1. jgill
    jgill avatar
    116 posts
    Member since:
    Jul 2005

    Posted 11 Sep 2010 Link to this post

    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>
  2. Rumen
    Admin
    Rumen avatar
    14080 posts

    Posted 15 Sep 2010 Link to this post

    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
  3. AT Murugan
    AT Murugan avatar
    4 posts
    Member since:
    Jun 2009

    Posted 31 Dec 2012 Link to this post

    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
  4. Rumen
    Admin
    Rumen avatar
    14080 posts

    Posted 02 Jan 2013 Link to this post

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