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

RadEditor.Content doesn't contain HTML

4 Answers 162 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 01 Mar 2011, 09:02 PM
I recently downloaded the trial version Telerik RadControls for ASP.NET AJAX for evaluation, and am having a problem with the RadEditor. I am attempting to have a user edit content via the editor and then save the HTML content to the database for later use in another area of the website. I have tried searching and have come up with nothing, so I figured I would ask here.

Whenever the user clicks to save the content, the HTML content is not saved. Instead the text is saved and all of the "<br>" tags are replaced with "\n". I have looked multiple times and it looks like I'm referencing the HTML correctly so I don't know why I'm not getting the actual HTML content. Below is the code for my .aspx page:

<telerik:RadEditor ID="RadContentEditor" Runat="server" Width="100%" Height="350px">
    <Tools>
    <telerik:EditorToolGroup Tag="MainToolbar">
        <telerik:EditorTool Name="Print" ShortCut="CTRL+P" />
        <telerik:EditorTool Name="AjaxSpellCheck" />
        <telerik:EditorTool Name="FindAndReplace" ShortCut="CTRL+F" />
        <telerik:EditorTool Name="SelectAll" ShortCut="CTRL+A" />
        <telerik:EditorTool Name="Cut" />
        <telerik:EditorTool Name="Copy" ShortCut="CTRL+C" />
        <telerik:EditorTool Name="Paste" ShortCut="CTRL+V" />
        <telerik:EditorToolStrip Name="PasteStrip">
        </telerik:EditorToolStrip>
        <telerik:EditorSeparator />
        <telerik:EditorSplitButton Name="Undo">
        </telerik:EditorSplitButton>
        <telerik:EditorSplitButton Name="Redo">
        </telerik:EditorSplitButton>
    </telerik:EditorToolGroup
    ******More tool groups here**********
</Tools>
<Content>
</Content>
<ImageManager UploadPaths="/BlastImages/" ViewPaths="/BlastImages/" />
<DocumentManager UploadPaths="/BlastDocuments/" ViewPaths="/BlastDocuments/" />
</telerik:RadEditor>
<br />
<table id="buttonTable" width="75%" align="center">
    <tr>
        <td style="width:50%; text-align:center;">
            <telerik:RadButton ID="saveContentButton" runat="server" ButtonType="LinkButton" OnClick="saveContentButton_OnClick" Text="Update Content">
                <Icon PrimaryIconCssClass="rbSave" />
            </telerik:RadButton>
        </td>
        <td style="width:50%; text-align:center;">
            <telerik:RadButton ID="cancelButton" runat="server" ButtonType="LinkButton" OnClick="cancelButton_OnClick" Text="Cancel">
                <Icon PrimaryIconCssClass="rbCancel" />
            </telerik:RadButton>
        </td>
    </tr>
</table>
<asp:SqlDataSource ID="sectionDS" runat="server" 
        ConnectionString="<%$ ConnectionStrings:MyConnString %>" 
        SelectCommand="SELECT [Content].id, [Content].page_id, [Content].section_name, [Content].html_content FROM [Content] INNER JOIN Pages ON [Content].page_id = Pages.id WHERE [Pages].page_url=@page_url" >
    <SelectParameters>
        <asp:SessionParameter Name="page_url" SessionField="page_url" />
    </SelectParameters>
</asp:SqlDataSource>

And this is the code-behind which handles the actual insert into the database:

 

 

 

protected void saveContentButton_OnClick(object sender, EventArgs e)
{
     PageHelper ph = new PageHelper();
  
     try
     {
          string section_id = (string)Session[Constants.SESSION_SECTION_ID];
          string section_content = RadContentEditor.Content;
          ph.updateSectionContent(section_id, section_content);
                      
          Response.Redirect("~/Web/Admin/Content/ManagePageSections.aspx");
     }
     catch (Exception ex)
     {
         Response.Redirect("~/Errors/UnhandledException.htm");
     }
}

4 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 02 Mar 2011, 10:37 AM
Hi Andrew,

You should not experience this problem. I tested the provided code and I was unable to reproduce the problem. You can see that the Content property returns HTML content along with <br/> tags in the following video http://screencast.com/t/SOAWnZ6w. You should see how this content is saved later in the DB and what is saving it as plain text, which is not related to RadEditor.
For your convenience I have also attached my test project.

My suggestion is to also review the following live demos: Save In Database and DataGrid Edit Template.

All the best,
Rumen
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Andrew
Top achievements
Rank 1
answered on 02 Mar 2011, 08:53 PM
You are indeed correct, that code does work correctly. However, due to a mistake on my part, I neglected to put in the code that runs on the loading of the page, which is exactly what I believe is causing the problem to occur:

protected override void Load_Page(object sender, EventArgs e)
{
    Dictionary<string, string> nameAndContent;
    PageHelper ph = new PageHelper();
  
    try
    {
        nameAndContent = ph.getSectionNameAndContentById((string)Session[Constants.SESSION_SECTION_ID]);
        sectionNameLabel.Text = nameAndContent[Constants.DB_CONTENT_SECTION_NAME];
        RadContentEditor.Content = nameAndContent[Constants.DB_CONTENT_HTML_CONTENT];
    }
    catch (Exception ex)
    {
        Response.Redirect("~/Errors/UnhandledException.htm");
    }
}

When the page is loaded, the editor gets a default content. This content is in the form of HTML that is stored in the database. For some reason, whenever the "save content" button is clicked, the result of RadEditor.Content returns whatever default content was assigned to it on the loading of the page instead of the updated content edited by the user.
0
Andrew
Top achievements
Rank 1
answered on 03 Mar 2011, 08:18 PM
I am positive of the issue now. Whenever I set the content of the RadEditor in the Page_Load method, it does not get updated. Eg. I set the content via "RadEditor1.Content = "Some content"", and when the user edits the text, it is not picked up by the RadEditor. When debugging I looked into the actual editor object and the value of "Content" is whatever the default text is (in this example it would be "Some Content").

Am I not setting the default content of the editor correctly?
0
Andrew
Top achievements
Rank 1
answered on 03 Mar 2011, 08:32 PM
I found the problem. Stupid mistake on my part, I forgot to test if the page was being loaded via a postback or not. Only set the content if(!Page.IsPostBack).
Tags
Editor
Asked by
Andrew
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or