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 Events

The current selection is:
The executed event is:
Simple symbol counter:
   
  
 
 
   

  • Client-Side Events

    RadEditor provides a rich client-side 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 

    The example above demonstrates some of the most useful editor Client-side Events for loading, editor command execution and content area selection. The OnClientSelection Changed event is very important and shown in action above, where the current editor content area selection is captured and displayed in a DIV element.

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.ClientsideEvents.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"/>
        
    </head>
    <body class="BODY">
        <form id="form1" runat="server">
                             
            <qsf:header id="Header1" runat="server" navigationlanguage="c#"/>
         <telerik:RadScriptManager ID="ScriptManager1" runat="server" />
            <qsf:InformationBox ID="InformationBox1" runat="server">
            <table>
                <tr>
                    <td rowspan="3" style="padding-right:30px;">
                        The current selection is:
             <div id="contentViewer" style="border:solid 1px #b1d8eb;overflow:scroll;background:white;width:200px;height:100px; padding: 3px; font:11px normalTahoma;width:300px;"></div>
                    </td>
                    <td>
                        The executed event is:
             <div id= "CommandMessage" style="border:solid 1px #b1d8eb;padding: 3px;background:white;font:11px normalTahoma;width:300px;"></div>
             </td>
                </tr>
                <tr>
                    <td rowspan="2">
                        Simple symbol counter:
             <div id= "counter" style="border:solid 1px #b1d8eb;padding: 0 3px;font:11px normalTahoma;background:white;width:300px;width:150px; height: 17px; line-height: 17px;"></div>
            
                     </td>
                     
                </tr>
                
            </table>
        
         </qsf:InformationBox>

                    <script type="text/javascript">
                //<![CDATA[    
                var messageDiv = $get('CommandMessage');    
                var contentViewer = $get('contentViewer');    
                var counter = $get('counter');
                
                function OnClientLoad(editor, args)
                {
                 counter.innerHTML = editor.get_html().length;
                
                    messageDiv.innerHTML = "OnClientLoad executed";
                    editor.attachEventHandler("onkeydown", function(e)
                    {
                       counter.innerHTML = editor.get_html().length;
                    });
                }
                
                function OnClientSelectionChange(editor, args)
                {
                   contentViewer.innerHTML = editor.getSelectionHtml();
                }


                function OnClientCommandExecuting(editor,args)
                {
                    //The command name
                    var commandName = args.get_commandName();
                    //The tool that initiated the command
                    var tool = args.get_tool();
                    //The selected value [if command is coming from a dropdown]
                    var value = args.get_value();
                    
                    //Perform some action
                    var message = "OnClientCommandExecuting.\nSelected value: " + value;
                    var answer = confirm(message + "\nExecute command " + commandName +"?");
                    
                    //Cancel the command execution by calling args.set_cancel(true);
                    args.set_cancel(!answer);
                }

                function OnClientCommandExecuted(editor,args)
                {                
                    messageDiv.innerHTML = "OnClientCommandExecuted. Command name:" + args.get_commandName();
                }    
                
                function OnClientModeChange(editor)
                {
                 messageDiv.innerHTML = "OnClientModeChange executed";
                }
                
                function OnClientSubmit(editor, args)
                {
                 messageDiv.innerHTML = "OnClientSubmit executed";
                 alert("OnClientSubmit executed");
                    
                }
                //]]>
                </script>    
         <telerik:RadEditor ID="RadEditor1" runat="server" SkinID="DefaultSetOfTools"
         OnClientLoad="OnClientLoad"
         OnClientCommandExecuted="OnClientCommandExecuted"
         OnClientCommandExecuting="OnClientCommandExecuting"    
         OnClientSelectionChange="OnClientSelectionChange"
         OnClientModeChange="OnClientModeChange"
         OnClientSubmit="OnClientSubmit">
             <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>
         <div style="padding: 5px" />
            <asp:Button ID="Button1" runat="server" Text="Submit" />
                
         <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