|
| 1 | +--- |
| 2 | +title: Changing Texts in the FormatBlock Dropdown Header of RadEditor for ASP.NET AJAX |
| 3 | +description: Learn how to customize the texts displayed in the FormatBlock dropdown header of RadEditor for ASP.NET AJAX. |
| 4 | +type: how-to |
| 5 | +page_title: Customize FormatBlock Dropdown Display Text in RadEditor for ASP.NET AJAX |
| 6 | +slug: customize-formatblock-dropdown-radeditor |
| 7 | +tags: radeditor, asp.net ajax, formatblock, dropdown, customization |
| 8 | +res_type: kb |
| 9 | +ticketid: 1686021 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | +<table> |
| 14 | +<tbody> |
| 15 | +<tr> |
| 16 | +<td>Product</td> |
| 17 | +<td>RadEditor for ASP.NET AJAX</td> |
| 18 | +</tr> |
| 19 | +<tr> |
| 20 | +<td>Version</td> |
| 21 | +<td>2025.1.218</td> |
| 22 | +</tr> |
| 23 | +</tbody> |
| 24 | +</table> |
| 25 | + |
| 26 | +## Description |
| 27 | + |
| 28 | +I want to change the texts displayed in the FormatBlock dropdown of RadEditor for ASP.NET AJAX. By default, the dropdown shows values such as "Normal," "Heading 1," "Heading 2," and "Heading 3." I need these values to be displayed as "Normale," "H1," "H2," and "H3" instead. |
| 29 | + |
| 30 | +This knowledge base article also answers the following questions: |
| 31 | +- How to modify FormatBlock display values in RadEditor for ASP.NET AJAX? |
| 32 | +- How to replace default text in RadEditor dropdowns? |
| 33 | +- How to customize FormatBlock display values in RadEditor? |
| 34 | + |
| 35 | +## Solution |
| 36 | + |
| 37 | +To achieve the desired customization, follow these steps: |
| 38 | + |
| 39 | +### 1. Configure RadEditor |
| 40 | + |
| 41 | +Use the following markup to define the `Paragraphs` and `EditorDropDown` for the FormatBlock tool. |
| 42 | + |
| 43 | +```html |
| 44 | +<telerik:RadEditor ID="Radeditor1" runat="server" Skin="WebBlue" OnClientSelectionChange="OnClientSelectionChange"> |
| 45 | + <Tools> |
| 46 | + <telerik:EditorToolGroup> |
| 47 | + <telerik:EditorDropDown name="FormatBlock"/> |
| 48 | + </telerik:EditorToolGroup> |
| 49 | + </Tools> |
| 50 | + <Paragraphs> |
| 51 | + <telerik:EditorParagraph Title="Normale" Tag="<P>" /> |
| 52 | + <telerik:EditorParagraph Title="H1" Tag="<H1>" /> |
| 53 | + <telerik:EditorParagraph Title="H2" Tag="<H2>" /> |
| 54 | + <telerik:EditorParagraph Title="H3" Tag="<H3>" /> |
| 55 | + </Paragraphs> |
| 56 | +</telerik:RadEditor> |
| 57 | +``` |
| 58 | + |
| 59 | +### 2. Apply JavaScript Customization |
| 60 | + |
| 61 | +Include the following JavaScript code to handle the `OnClientSelectionChange` event. This code replaces the default dropdown values with the desired ones. |
| 62 | + |
| 63 | +```javascript |
| 64 | +<script type="text/javascript"> |
| 65 | + function OnClientSelectionChange(editor, args) { |
| 66 | + var tool = editor.getToolByName("FormatBlock"); |
| 67 | + if (tool) { |
| 68 | + setTimeout(function () { |
| 69 | + var value = tool.get_value(); |
| 70 | + switch (value) { |
| 71 | + case "Normal": |
| 72 | + value = value.replace("Normal", "Normale"); |
| 73 | + break; |
| 74 | + case "Heading 1": |
| 75 | + value = value.replace("Heading 1", "H1"); |
| 76 | + break; |
| 77 | + case "Heading 2": |
| 78 | + value = value.replace("Heading 2", "H2"); |
| 79 | + break; |
| 80 | + case "Heading 3": |
| 81 | + value = value.replace("Heading 3", "H3"); |
| 82 | + break; |
| 83 | + case "Heading 4": |
| 84 | + value = value.replace("Heading 4", "H4"); |
| 85 | + break; |
| 86 | + } |
| 87 | + tool.set_value(value); |
| 88 | + }, 0); |
| 89 | + } |
| 90 | + } |
| 91 | +</script> |
| 92 | +``` |
| 93 | + |
| 94 | +### Explanation |
| 95 | + |
| 96 | +- The `OnClientSelectionChange` event is triggered whenever a selection is made in the FormatBlock dropdown. |
| 97 | +- The `getToolByName` function retrieves the FormatBlock tool. |
| 98 | +- The `setTimeout` ensures the changes are applied after the dropdown value is updated. |
| 99 | +- A switch statement replaces the default dropdown values with the customized ones. |
| 100 | + |
| 101 | +## See Also |
| 102 | + |
| 103 | +- [RadEditor Documentation](https://www.telerik.com/products/aspnet-ajax/documentation/knowledge-base/editor-show-pixel-value-in-real-font-size-dropdown) |
| 104 | +- [Change Pixel to Point Size in RadEditor Forum Discussion](https://www.telerik.com/forums/change-pixel-to-point-size-in-radeditor?#3083512) |
0 commit comments