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 / Auto-save demo

Autosave RadEditor's content every 15 seconds:
   
  
 
 
   



The Saved content will be displayed below:

  • Autosave RadEditor's content

    This example demonstrates how to implement autosave functionality using RadEditor and MS AJAX Timer. In the example the editor's content is read on the server in the Timer OnTick event, and fed into a label. In a real world scenario the content would be saved into a database or other temporary storage.

    The Timer is configured to perform an AJAX request every 15 seconds. However, it is not advisable to do so without checking whether the user is using the AJAX SpellCheck at the time of sending the content. While it is in AJAX SpellCheck mode, the editor's content contains additional formatting inserted by the spellchecker to highlight mistaken words. As a result, it is not desireable to save the content while in spellcheck mode.

    RadEditor provides events that are raised when a spellcheck starts and ends. The example demonstrates how to attach to these events, and stops the Timer during spellchecking, and restarts it when the spellcheck is finished.

    <script type="text/javascript"
       
    function OnClientLoad(sender, args) 
        { 
           
    var timer = $find("<%=Timer1.ClientID %>")
            
           
    //Attach to the spellCheckLoaded event as the spell itself is loaded with AJAX 
           
    sender.add_spellCheckLoaded(
               
    function() 
                {
                   
    var spell = sender.get_ajaxSpellCheck()
                
                   
    spell.add_spellCheckStart(
                       
    function(sender, args) 
                        { 
                            timer._stopTimer()
    ;
                       
    });
                
                   
    spell.add_spellCheckEnd(
                       
    function(sender, args) 
                        {
                           
    //Restart the timer; 
                           
    timer._startTimer();
                       
    });
               
    } );
           
    }
    </script

Source Code

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

    <%@ 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.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <qsf:HeadTag ID="Headtag1" runat="server" />
    </head>
    <body class="BODY">

        <script type="text/javascript">
            function OnClientLoad(sender, args)
            {
                var timer = $find("<%= Timer1.ClientID %>");
                
                startCounter();
            
                //Attach to the spellCheckLoaded event as the spell itself is loaded with AJAX
                sender.add_spellCheckLoaded(function()
                    {
                        var spell = sender.get_ajaxSpellCheck();
                                                
                        spell.add_spellCheckStart(function(sender, args)
                        {
                            timer._stopTimer();
                            
                            //Stop counter
                            stopCounter();
                        });
                                    
                        spell.add_spellCheckEnd(function(sender, args)
                        {
                            //Restart the timer;
                            timer._startTimer();
                            
                            //Restart counter
                            startCounter();
                        });
                    }
                );
            }
            
            
            //======================================== UI update for the remaining seconds =======================================//
            var initialSeconds = 15;
            var currentSeconds = initialSeconds;
            var interval = null;
            function startCounter()
            {
                if (!interval)
                {
                     currentSeconds = initialSeconds;
                     interval = window.setInterval(function()
                     {
                        if (currentSeconds > 0)
                        {
                            currentSeconds--;
                        }
                        else
                        {
                            currentSeconds = initialSeconds;
                        }
                        
                        var span = document.getElementById("remainingSeconds");
                        span.innerHTML = currentSeconds;
                        
                     }, 1000);
                }
            }
                            
            function stopCounter()
            {
                if (interval) window.clearInterval(interval);
                interval = null;
            }
            
            //===============================================================================================================//
        </script>

        <form id="form1" runat="server">
            <qsf:Header ID="Header1" runat="server" NavigationLanguage="VB" />
            <telerik:RadScriptManager ID="ScriptManager1" runat="server" />
            <qsf:InformationBox ID="InformationBox1" runat="server" style="font-size: 18px;">
                    Autosave RadEditor's content every 15 seconds: <span style="color:#bb0000;font-size:15px;" id="remainingSeconds"></span>
            </qsf:InformationBox>
            <telerik:RadEditor runat="server" ID="RadEditor1" OnClientLoad="OnClientLoad" SkinID="DefaultSetOfTools"
                Height="400px">
                <ImageManager ViewPaths="~/Editor/Img/UserDir/Marketing,~/Editor/Img/UserDir/PublicRelations"
                    UploadPaths="~/Editor/Img/UserDir/Marketing,~/Editor/Img/UserDir/PublicRelations"
                    DeletePaths="~/Editor/Img/UserDir/Marketing,~/Editor/Img/UserDir/PublicRelations">
                </ImageManager>
                <Content>
        
                </Content>
            </telerik:RadEditor>
            <asp:Timer ID="Timer1" runat="server" Interval="15000" OnTick="Timer1_Tick">
            </asp:Timer>
            <br />
            <br />
            <br />
            <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Timer1" />
                </Triggers>
                <ContentTemplate>
                        <span style="font-weight:bold;font-size: 15px;margin-bottom: 10px;">The Saved content will be displayed below:</span>
                        <div style="border: solid 3px #d6eefd; padding:5px; ">
                            <div style="border: solid 1px black; line-height: 22px; padding: 0 4px">
                                <asp:Label runat="server" ID="lbl1"/>
                            </div>
                        </div>
                </ContentTemplate>
            </asp:UpdatePanel>
            <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