Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q2 2011 released 07/12/2011
select

Editor / Client-side API

   
  
 
 
   



  • Client-Side API

    RadEditor provides a rich Client-Side API and event model. You can attach custom client-script code (JavaScript) to a number of client-side events fired by the editor. All client-side events are exposed as string properties to the RadEditor instance with the value being the name of the JavaScript function to be called. 
    Below is a list of all client-side events and methods that are currently supported by RadEditor:

    Events

    1. OnClientInit - fired before RadEditor initialization
    2. OnClientLoad  - fired after the RadEditor is loaded on the client
    3. OnClientCommandExecuting - fired just before a command is executed
    4. OnClientCommandExecuted - fired after a command is executed 
    5. OnClientSelectionChange - fired when the selection within the editor content area has changed
    6. OnClientModeChange - fired when the editor's mode is changed
    7. OnClientSubmit - fired when the editor saves its content just before a postback/ajax request 

    Methods

    1. pasteHtml - Pastes HTML content to the cursor position.
    2. set_html - Replaces the current content with a new one.
    3. setFocus - Sets the focus on RadEditor.
    4. get_html - Returns the editor content as HTML.
    5. get_text - Returns the editor content as plain text.
    6. getSelection - Returns a reference to the current RadEditorSelection object.
    7. getSelectionHtml - Returns the HTML of the selection.
    8. fire - Executes RadEditor commands.
    9. getToolByName - Returns tool so for the purposes of client-side manipulation.
    10. get_contentArea - Returns a reference to the editor's content area.
    11. showExternalDialog - Shows a dialog with the supplied arguments.
    12. attachEventHandler - Attaches an event to its handler.

    More information is available in the following help article: Getting familiar with Client-Side API.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Theme="Default" Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs"
        Inherits="Telerik.Web.Examples.Editor.ClientsideAPI.DefaultCS" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag ID="Headtag1" runat="server" />
        <script type="text/javascript">
            function ExecuteCommand(command) {
                $find("RadEditor1").fire(command);
            }
            function AlertSelectedHtml() {
                alert($find("RadEditor1").getSelectionHtml());
            }
            function SetHtml() {
                var newValue = $get('textHtml').value;
                $find("RadEditor1").set_html(newValue);
            }
        </script>
    </head>
    <body class="BODY">
        <form id="form1" runat="server">
        <qsf:Header ID="Header1" runat="server" NavigationLanguage="c#" />
        <telerik:RadScriptManager ID="ScriptManager1" runat="server" />
        <qsf:ConfiguratorPanel runat="server" ID="ConfigurationPanel1" Enabled="true" Title="External Buttons"
            Expanded="true" Style="text-align: left;" HorizontalAlign="Right">
            <input type="button" value="SelectAll" class="button" onclick="ExecuteCommand('SelectAll')" />
            <input type="button" value="Bold" class="button" onclick="ExecuteCommand('Bold')" />
            <input type="button" value="Italic" class="button" onclick="ExecuteCommand('Italic')" />
            <input type="button" value="Underline" class="button" onclick="ExecuteCommand('Underline')" />
            <input type="button" value="StrikeThrough" class="button" onclick="ExecuteCommand('StrikeThrough')" />
            <input type="button" value="ConvertToUpper" class="button" onclick="ExecuteCommand('ConvertToUpper')" />
            <input type="button" value="ConvertToLower" class="button" onclick="ExecuteCommand('ConvertToLower')" />
        </qsf:ConfiguratorPanel>
        <telerik:RadEditor ID="RadEditor1" runat="server">
            <Content>
                 <img alt="product logo" src="../../Img/productLogoLight.gif" /> is the successor of the well known industry standard Editor for ASP.NET. The tight integration with ASP.NET AJAX and the powerful new capabilities make Telerik's WYSIWYG Editor a flexible and lightweight component, turning it into the fastest loading Web Editor. Among the hottest features are:
                        <ul>
                        <li><em>Single-file, drag-and-drop deployment</em></li>
                        <li><em>Built on top of ASP.NET AJAX</em></li>
                        <li><em>Unmatched loading speed with new semantic rendering </em></li>
                        <li><em>Full keyboard accessibility</em></li>
                        <li><em>Flexible Skinning mechanism</em></li>
                        <li><em>Simplified and intuitive toolbar configuration</em></li>
                        <li><em>Out-of-the-box XHTML-enabled output</em></li>
                        </ul>
            </Content>
        </telerik:RadEditor>
        <br />
        <div class="module">
            <input type="button" value="Alert SelectedHtml" onclick="AlertSelectedHtml()" />
        </div>
        <br />
        <div class="module">
            <input type="button" value="Set New Html to the RadEditor" onclick="SetHtml()" />
            <input type="text" value="New HTML" id="textHtml" />
        </div>
        <qsf:Footer runat="server" ID="Footer1" />
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451