Whats the difference between OnClientCommandExecuting and RadEditorCommandList?

2 posts, 0 answers
  1. Andy
    Andy  avatar
    6 posts
    Member since:
    Aug 2011

    Posted 04 Nov 2011 Link to this post

    I've customized the editor toolbars by removing some buttons while adding my own custom buttons.  I've implemented a clientside OnClientCommandExecuting handler to intercept and cancel keyboard shortcuts to the removed editor buttons.  I also want to handle click events from the editor toolbar custom buttons. 

    Telerik documentation says to add onclick handlers to the editor's RadEditorCommandList.  But, I've noticed that custom button click events are first processed by the OnClientCommandExecuting handler before they get to the RadEditorCommandList handlers.  

    What is the difference between using these two handlers?  The custom buttons will instigate serverside save and saveas functionality via an ajax post.  I'ld prefer to combine everything into the OnClientCommandExecuting handler, and to launch save/saveas ajax posts from there.  After each launch I will cancel the click event.


    <script type="text/javascript">
      
        function OnClientCommandExecuting(editor, args) {
           if ("Save" == args.get_commandName()) {
                alert("OnClientCommandExecuting Save"); 
                args.set_cancel(true);          
            } else if ("SaveAs" == args.get_commandName()) {
                alert("OnClientCommandExecuting SaveAs");
                args.set_cancel(true); 
            }
        } //EOF OnClientCommandExecuting
      
    </script>
      
    <telerik:RadEditor ID="telerikeditor" Runat="server" 
                       OnClientLoad="onClientLoad"
                       OnClientCommandExecuting="OnClientCommandExecuting">
        <Tools>
            <telerik:EditorToolGroup Tag="grpInputOutput">
                <telerik:EditorTool ImageUrl="Images/radeditorSave.gif" 
                    Name="Save" ShowText="False" 
                    Text="Save" />
                <telerik:EditorTool ImageUrl="Images/radeditorSaveAs.gif" 
                    Name="SaveAs" ShowText="False" 
                    Text="Save As" />
                <telerik:EditorSeparator />     
            </telerik:EditorToolGroup>
         </Tools>
         <Content>
         </Content>
    </telerik:RadEditor>    
              
    <script type="text/javascript"
         //locate this script after the radeditor HTML declaration
        RadEditorCommandList["Save"] = function(commandName, editor, oTool) {
            alert("RadEditorCommandList Save");
        }
    </script>
  2. Rumen
    Admin
    Rumen avatar
    14459 posts

    Posted 09 Nov 2011 Link to this post

    Hi Andy ,

    Yes, the OnClientCommandExecuting event is executed before the RadEditorCommandList so that you can cancel the command execution. This is more suitable for canceling the built-in commands, but of course works for custom ones. You can implement your solution by combining everything into the OnClientCommandExecuting handler, and to launch save/saveas ajax posts from there.


    Best wishes,
    Rumen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top