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

Custom Commands

1 Answer 59 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Moustafa
Top achievements
Rank 1
Moustafa asked on 26 Feb 2011, 10:47 AM
Hi team,
I do all the steps described in your site to create custom commands in the editor and it worked successfully, I create the editor in a user control and add this control to my page , its ok great .

I do the following scenario

  1. Add the editor in user control (say  UCtrl ) with the new custom button.
  2. Add two instance of the user control (Say UCtrl1,UCtrl2 ) in the same page.
  3. unfortunately when I click the custom command button in the editor in the first instance( UCtrl1 ) , the execution of the comand occurs in the second instance (UCtrl2)

 

Breifly the command executed in the last instance of control added to the page.

Is there any solution for this issues??

Tools and Technologies

ajax control for asp.net  version 9 Q3.
IE as web browser
windows 7 as an operating system
microsoft asp.net 3.5
sql server 2005 database

1 Answer, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 02 Mar 2011, 03:19 PM
Hi Moustafa,

This problem is not directly related to RadEditor but is a general ASP.NET knowledge. In case where multiple instances of a WebUserControl, that contains JavaScript code, are registered on a page, the JavaScript of the usercontrols is overwriting itself, thus the code of the last registered control is active. For example, if you are referencing RadEditor with its ClientID ( var editor = $find("<%=RadEditor1.ClientID"); ) the editor variable will be defined multiple times and only the last one will be active, thus the custom command will execute the functions to the last instance of RadEditor.

To avoid this behavior you need to use the editor parameter of the custom command as reference to the current RadEditor, e.g.:
Telerik.Web.UI.Editor.CommandList["Custom1"] = function (commandName, editor, args)
{
    editor.pasteHtml("Executed Custom Command for UserControl with ID: " + editor.get_id());
};

Please take a look at the attached sample page demonstrating the correct and incorrect approach.

Best wishes,
Dobromir
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!
Tags
Editor
Asked by
Moustafa
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Share this question
or