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

Add image upload icon - lose functionality

7 Answers 62 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Amanda
Top achievements
Rank 1
Amanda asked on 14 Mar 2011, 04:46 PM
So, if you want to add and image upload icon - you lose the rest of the functionality of the radEditor?  How do I retain the other information in the menu of the radEditor yet add the ability to add images?

Thanks in advance.

7 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 15 Mar 2011, 01:23 PM
Hi Amanda,

You can add a button programmatically without deleting the whole toolbar by using this example method:
protected void Page_Load(object sender, EventArgs e)
    {
        //make sure that the main tools are already loaded before adding your own
        RadEditor1.EnsureToolsFileLoaded();
 
        EditorToolGroup toolgroup = new EditorToolGroup();
        RadEditor1.Tools.Add(toolgroup);
        EditorTool custom1 = new EditorTool();
        custom1.Name = "Custom1";
        custom1.ShortCut = "CTRL+1";
        toolgroup.Tools.Add(custom1);
 
    }

Note the call to the EnsureToolsFileLoaded() method. Without it you will lose the default toolbar.

Alternatively, you could copy the default toolsfile, modify it to your liking and set it as an external toolsfile.

How to add custom buttons and implement their functionality is explained in the documentation: http://www.telerik.com/help/aspnet-ajax/editor-adding-your-own-buttons.html

Greetings,
Marin
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
Amanda
Top achievements
Rank 1
answered on 15 Mar 2011, 03:19 PM
Thanks,  I have one more question.  After you save the radEditor - and you go back to edit it - how do you call it in the code behind to show what is already in the database?  I have tried radEdit.Text = dt.rows[0][""].ToString(); - that doesn't work though.  Thank you!
0
Marin Bratanov
Telerik team
answered on 16 Mar 2011, 04:58 PM
Hi Amanda,

The Text property is read-only and returns the content as plain text (without the HTML tags). To set the current RadEditor content you can use its Content property, as it is read-write and supports HTML formatting. For example:
RadEditor1.Content = "Sample Content";

The approach when using RadEditor with databases is illustrated in the following demo: http://demos.telerik.com/aspnet-ajax/editor/examples/saveindatabase/defaultcs.aspx

Please note that RadEditor works primarily on the client, so you should specifically make sure to call the code-behind function that alters the content and reload the page so that the Editor gets your new content. For example:
protected void ChangeContent(object sender, EventArgs e)
{
    editor1.Content = "sample content";
}

Try using this function in the code-behind with these two versions of the aspx page:
<asp:ScriptManager runat="server"></asp:ScriptManager>
<telerik:RadEditor runat="server" ID="editor1"></telerik:RadEditor>
<asp:Button runat="server" ID="changer" Text="change content" OnClick="ChangeContent" />
and:
<asp:ScriptManager runat="server"></asp:ScriptManager>
<telerik:RadEditor runat="server" ID="editor1"></telerik:RadEditor>
<asp:Button runat="server" ID="changer" Text="change content" OnClick="ChangeContent"
         OnClientClick="javascript:void(0);return false;" />

Note that in the second version I forcefully cancel the postback and the new content is not set in the editor.


Best wishes,
Marin
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
Amanda
Top achievements
Rank 1
answered on 17 Mar 2011, 09:40 PM
Okay - so I have images imbedded into the text that have been saved in the database.  I am able to get the text out - but the images are not displaying because of the ToString() at the end of the call.  How can I get the images to show as well - this is what I have now.

radEdit.Content = dt.Rows[0]["News"].ToString();
0
Marin Bratanov
Telerik team
answered on 18 Mar 2011, 04:29 PM
Hi Amanda,

You need to provide a valid HTML string for the Editor's Content property. In your case you need to parse your  data before you set it in the editor and replace the inline images with corresponding <img /> tags. How to do that depends on your custom database, its content and your scenario.


Regards,
Marin
the Telerik team
0
Amanda
Top achievements
Rank 1
answered on 18 Mar 2011, 09:30 PM
When I am saving it - this is what is being saved:
<img alt=\"\" src=\"/Share_Images/1XXX_Web.JPG\" />
0
Marin Bratanov
Telerik team
answered on 21 Mar 2011, 06:24 PM
Hi Amanda,

The string you have is not valid XHTML. You need to use the Replace() method and remove the escaping from the quotation marks before passing it to the Editor.


All the best,
Marin
the Telerik team
Tags
Editor
Asked by
Amanda
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Amanda
Top achievements
Rank 1
Share this question
or