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

Change buttons from Javascript

7 Answers 92 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Meerkat
Top achievements
Rank 1
Meerkat asked on 06 Oct 2008, 04:35 PM

Hello, I have tried all day but have been unable to find out how to show/hide toolbars/buttons from Javascript.

I am controlling the editor from silverlight so I am assuming I need to use Javascript.

I would like the buttons shown in the RadEditor to depend on something the user enters.
I have edited a couple of ToolsFile.xml files to contain the buttons I require.
Calling either of the following 2 Javascript functions does nothing at all.

  <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

  <script language="javascript" type="text/javascript">

  function setShortTools()
    {
    var editor = $find("<%= RadProfileEditor.ClientID %>");
    editor.ToolsFile = "~/RadControls/Editor/MyToolsFileShort.Xml";
    }

  function setLongTools()
    {
    var editor = $find("<%= RadProfileEditor.ClientID %>");
    editor.ToolsFile = "~/RadControls/Editor/MyToolsFileLong.Xml";
    }
 
  </script>

  </telerik:RadCodeBlock>

Can anyone please tell me how to change RadEditor Buttons using Javascript (or any other method that works from Silverlight)
Many thanks in advance.
Pete

7 Answers, 1 is accepted

Sort by
0
Accepted
Todd Anglin
Top achievements
Rank 2
answered on 06 Oct 2008, 08:14 PM
Hello Pete-

Unfortunately, I don't think there is currently any client-side approach for changing a RadEditor's tool set. These tools are initilized on page load and serialized as JSON to the client. I would expec your only options for now are either A) use RadAjax's client-side API to fire an Ajax update of RadEditor from your SL app and then change the tools file on the server, or B) try to create a web service that returns the required RadEditor toolbar JSON and then use the client-side set_toolJSON to update the toolbar.

I'm not sure if that later will work or how you'd get the JSON on the server to send to the client, but maybe the RadEditor devs can chime-in with an idea. At the very least, there is no simple approach for removing tools from the toolbar client-side (though you an easily disable tools client-side). 

Hope that helps clarify the situation.

-Todd
0
Meerkat
Top achievements
Rank 1
answered on 07 Oct 2008, 07:27 AM
Fair enough.
Many thanks for letting me know. I will try to think of something else.
Regards,
Pete.
0
Tervel
Telerik team
answered on 07 Oct 2008, 07:44 AM
Hello all,

RadEditor for ASP.NET AJAX features a full-blown client-side API for creating buttons., dropdowns and toolbars.
However, generating and configuring an editor like this fully on the client-side requires good javascript skills as well as is prone to error. I would not recommend such an approach in this scenario.

It is better to have 2 or 3 editors (each with a different tools file) loaded on the page - in hidden DIV's. Then you will be able to show whichever editor you need by chaning the DIV's style.display property. This approach is simple and efficient, because the editors are able to detect whether they (or a parent of theirs) is invisible and do not run their initialization code (until they are made visible). Thus the time it takes for the page to load should not change much.

All the best,
Tervel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Todd Anglin
Top achievements
Rank 2
answered on 07 Oct 2008, 03:16 PM
I suppose with that approach the only thing the developer must also remember is that the content would need to be manually "sync'd" between editors as their shown and hidden. Clearly, the client-side API makes that a pretty easy task, but a critical step to making the multi-editor approach work. 

Out of curiosity, is it possible to generate a RadEditor's toolbar JSON server-side, send it to the client via a web service (let's say), and then re-init the toolbar with the new JSON? Since a single sprite image is used for toolbars, I don't think extra images would need to be downloaded, so it seems like it could work. I'm just not sure what problems are created by trying to re-init a toolbar without re-initing the whole Editor.

-Todd
0
Tervel
Telerik team
answered on 08 Oct 2008, 06:18 AM
Hi Todd,

"Out of curiosity, is it possible to generate a RadEditor's toolbar JSON server-side, send it to the client via a web service (let's say), and then re-init the toolbar with the new JSON"

Yes, it is possible, however it will require quite a bit of code on the server, and a hack or two on the client (to "trick" the editor to re-initialize).

However, as far as the developer is concerned, simplicity is the name of the game - and this is how we try to do things with the RadEditor - e.g. making it very easy to configure, yet very flexible at the same time to cover the whole range of scenarios where people want to use it. Usually to achieve a goal there is more than one possibility, and usually the simplest approach is the best one.


Kind regards,
Tervel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Ian Russell
Top achievements
Rank 1
answered on 28 Apr 2009, 04:46 PM
Question: can I wrap the editor with an ajax panel and wire up a custom button to make an ajax request that will load a different tools file? If yes, can you provide an example please?
0
Tervel
Telerik team
answered on 29 Apr 2009, 07:23 AM
Hello Attila,

In fact, the default editor example available here does something very similar to that:
http://demos.telerik.com/aspnet-ajax/editor/examples/default/defaultcs.aspx

There is a radiobuttonlist control which will change the tools file of the editor by means of AJAX request.
The example  uses a standard <asp:UpdatePanel> instead of RadAjaxPanel, but this is  a minor difference.

Greetings,
Tervel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Editor
Asked by
Meerkat
Top achievements
Rank 1
Answers by
Todd Anglin
Top achievements
Rank 2
Meerkat
Top achievements
Rank 1
Tervel
Telerik team
Ian Russell
Top achievements
Rank 1
Share this question
or