Skip to content

Commit a7a6606

Browse files
github-actions[bot]KB Bot
and
KB Bot
authored
Added new kb article editor-prevent-backspace-radeditor-disabled (#602)
Co-authored-by: KB Bot <[email protected]>
1 parent 2e76c02 commit a7a6606

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: Disabling Content Removal Using Backspace when RadEditor is disabled
3+
description: Learn how to prevent content removal using the backspace key in RadEditor by disabling editing and making it non-editable.
4+
type: how-to
5+
page_title: How to Prevent Content Deletion with Backspace when RadEditor is disabled
6+
slug: editor-prevent-backspace-radeditor-disabled
7+
tags: radeditor, asp.net ajax, disable editing, non-editable, backspace, prevent content removal
8+
res_type: kb
9+
ticketid: 1666216
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>RadEditor for ASP.NET AJAX</td>
19+
</tr>
20+
<tr>
21+
<td>Version</td>
22+
<td>all</td>
23+
</tr>
24+
</table>
25+
26+
## Description
27+
Even after setting `enableEditing` and `set_editable` to `false`, it's still possible to remove or modify the content in RadEditor using the backspace key. How can this behavior be disabled to prevent content removal?
28+
29+
This KB article also answers the following questions:
30+
- How to make RadEditor content non-editable?
31+
- How to disable the backspace key in RadEditor?
32+
- How to prevent content modification in RadEditor?
33+
34+
## Solution
35+
To prevent users from removing content using the backspace key in [RadEditor](https://docs.telerik.com/devtools/aspnet-ajax/controls/editor/overview) while keeping the editor non-editable, follow the steps below:
36+
37+
1. **Disable Editing and Make Non-Editable:**
38+
39+
Set the editor to non-editable mode by using the `enableEditing(false)` and `set_editable(false)` methods.
40+
41+
2. **Disable the Backspace Key:**
42+
43+
Add an event listener to the RadEditor content area to disable the backspace key functionality.
44+
45+
````ASPX
46+
<script>
47+
function OnClientLoad(editor, args) {
48+
editor.enableEditing(false);
49+
editor.set_editable(false);
50+
51+
var contentArea = editor.get_contentArea();
52+
contentArea.addEventListener('keydown', function (e) {
53+
if (e.key === 'Backspace') {
54+
e.preventDefault();
55+
}
56+
});
57+
}
58+
</script>
59+
````
60+
61+
3. **Integrate the Event Listener with the RadEditor:**
62+
63+
Ensure the `OnClientLoad` event is properly configured in your RadEditor definition.
64+
65+
````aspx
66+
<telerik:RadEditor ID="RadEditor1" runat="server" OnClientLoad="OnClientLoad">
67+
<Content>some content</Content>
68+
</telerik:RadEditor>
69+
````
70+
71+
This configuration disables the backspace key, preventing content removal and modification, while keeping the editor in a non-editable state.
72+
73+
Additionally, to disable other editing features such as copy, typing, enter, delete, and pasting content, you can use the `OnClientCommandExecuting` and `OnClientPasteHtml` events:
74+
75+
```asp
76+
<telerik:RadEditor runat="server" ID="RadEditor1" ContentAreaMode="iframe" OnClientLoad="OnClientLoad" OnClientCommandExecuting="OnClientCommandExecuting" OnClientPasteHtml="OnClientPasteHtml">
77+
<Content>test content</Content>
78+
</telerik:RadEditor>
79+
```
80+
81+
````ASPX
82+
<script>
83+
function OnClientCommandExecuting(editor, args) {
84+
args.set_cancel(true);
85+
}
86+
function OnClientPasteHtml(editor, args) {
87+
args.set_cancel(true);
88+
}
89+
</script>
90+
````
91+
92+
## See Also
93+
94+
- [RadEditor Overview](https://docs.telerik.com/devtools/aspnet-ajax/controls/editor/overview)
95+
- [RadEditor Client-Side Programming](https://docs.telerik.com/devtools/aspnet-ajax/controls/editor/client-side-programming/overview)

0 commit comments

Comments
 (0)