Change buttons from Javascript

8 posts, 1 answers
  1. Meerkat
    Meerkat avatar
    64 posts
    Member since:
    Feb 2007

    Posted 06 Oct 2008 Link to this post

    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

  2. Answer
    Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 06 Oct 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Meerkat
    Meerkat avatar
    64 posts
    Member since:
    Feb 2007

    Posted 07 Oct 2008 Link to this post

    Fair enough.
    Many thanks for letting me know. I will try to think of something else.
    Regards,
    Pete.
  5. Tervel
    Admin
    Tervel avatar
    1337 posts

    Posted 07 Oct 2008 Link to this post

    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.
  6. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 07 Oct 2008 Link to this post

    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
  7. Tervel
    Admin
    Tervel avatar
    1337 posts

    Posted 08 Oct 2008 Link to this post

    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.
  8. Ian Russell
    Ian Russell avatar
    19 posts
    Member since:
    Feb 2004

    Posted 28 Apr 2009 Link to this post

    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?
  9. Tervel
    Admin
    Tervel avatar
    1337 posts

    Posted 29 Apr 2009 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017