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

How can I clear Undo/Redo history on postback?

5 Answers 245 Views
Editor
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 2
David asked on 17 Dec 2009, 12:13 AM
We are using an ajaxified Dropdown list and RadEdit to edit different content blobs from a database. We have found that the Undo function will load the content of the RadEdit from a previous content loaded/replaced by ajax event.

So my question is, how -- using js and/or code-behind -- can I clear the Undo history?

5 Answers, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 17 Dec 2009, 01:04 PM
Hello David,

The following example demonstrates  how to clear the history:

<telerik:radeditor runat="server" ID="RadEditor1"></telerik:radeditor>
<div onclick="SetContent(this);" id="Div1">sample content DIV 1</div>
<div onclick="SetContent(this);" id="Div2">sample content DIV 2</div>
<script type="text/javascript">
    function SetContent(oDiv) {
        var editor = $find("<%=RadEditor1.ClientID%>");
  
        editor.get_commandsManager()._clearCommandsToRedo();
  
        var manager = editor.get_commandsManager();
        var length = manager.getCommandsToUndo().length;
        for (var i = 0; i < length; i++) {
            manager.removeCommandAt(0);
        }
  
        editor.get_document().body.innerHTML = oDiv.innerHTML;
    }
</script>

I hope this helps.

Greetings,
Dobromir
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
David
Top achievements
Rank 2
answered on 20 Dec 2009, 06:54 PM
Sorry, I should have specified my version. The affected project is RadControls for ASP.NET, Q1 2009 (last update), and the solution halts with a js error.

0
Rumen
Telerik team
answered on 21 Dec 2009, 09:08 AM
Hi David,

Thank you for the additional information.

Here is how to reset the Undo list of RadEditor Classic:

<rade:radEditor id="RadEditor1" ImagesPaths="~/" UploadImagesPaths="~/" runat="server" >
         sample content
</rade:radEditor>
<div onclick="SetContent(this);" id="Div1">sample content DIV 1</div>
<div onclick="SetContent(this);" id="Div2">sample content DIV 2</div>
<script type="text/javascript">
function SetContent(oDiv)
{
   var editor = <%=RadEditor1.ClientID%>
 
    editor.CommandsManager.ClearCommandsToRedo();
    var manager = editor.CommandsManager;
    var length = manager.GetCommandsToUndo().length;
    for (var i=0; i < length; i++)
    {
        manager.RemoveCommandAt(0);
    }

   editor.Document.body.innerHTML = oDiv.innerHTML;
}
</script>


Best regards,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Martin
Top achievements
Rank 1
answered on 25 Jan 2010, 09:33 PM
David the below example is great. I will need one more thing. When there is nothing in history how can I make the Undo button disabled. When the history is cleared the button still remains active. thans.

    
function SetContent(oDiv) {
        var editor = $find("<%=RadEditor1.ClientID%>");
  
        editor.get_commandsManager()._clearCommandsToRedo();
  
        var manager = editor.get_commandsManager();
        var length = manager.getCommandsToUndo().length;
        for (var i = 0; i < length; i++) {
            manager.removeCommandAt(0);
        }
  
        editor.get_document().body.innerHTML = oDiv.innerHTML;
    }
0
Martin
Top achievements
Rank 1
answered on 26 Jan 2010, 04:26 PM
I've figured it out.

 

var myCancelTool = sender.getToolByName("Cancel");

 

myCancelTool.setState(-1);

Tags
Editor
Asked by
David
Top achievements
Rank 2
Answers by
Dobromir
Telerik team
David
Top achievements
Rank 2
Rumen
Telerik team
Martin
Top achievements
Rank 1
Share this question
or