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

Ajax / Client-side Events

Event log:







  • This example illustrates how to use the client-side API of RadAjaxPanel to implement a simple text editor.

    The events used here are: OnRequestStart and OnResponseEnd.
    The event handler functions for these are defined as follows:

    <ClientEvents OnResponseEnd="OnResponseEnd" OnRequestStart="OnRequestStart"></ClientEvents>

    The OnRequestStart event fires just before the XmlHttpRequest is sent to the server. In this example it is used to disable controls on the form and displaying status information. Moreover, we are also using this event to prompt the user to cancel the AJAX request if he wishes to.

    The OnResponseEnd event fires when the html on the page has been updated by an AJAX request. We use it in this example to update status information and re-enable form controls to allow the user to continue work.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="c#" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.AJAXExamplesCSharp.AJAX.Examples.Panel.ClientEvents.DefaultCS" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="telerik" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <telerik:HeadTag runat="server" ID="Headtag1"></telerik:HeadTag>
        <!-- custom head section -->
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

            <script type="text/javascript">
            
            function pageLoad()
            {
                logEvent("pageLoad fired");
            }
            
         function OnRequestStart(sender, args)
         {
         logEvent("OnRequestStart (" + args.get_eventTarget() + ") fired");
             var statusLabel = document.getElementById("<%= statusLabel.ClientID %>");
             var txtBody = document.getElementById("<%= txtBody.ClientID %>");
             var sendMessage = document.getElementById("<%= sendMessage.ClientID %>");                 
             var saveDraft = document.getElementById("<%= saveDraft.ClientID %>");
             var restoreDraft = document.getElementById("<%= restoreDraft.ClientID %>");
            
             if(args.get_eventTarget().indexOf("saveDraft") != -1)
                {
             if(!window.confirm("Save draft?"))
                 return false; // Cancel ajax request.
                 statusLabel.innerHTML = "Saving...";
                }
                else if(args.get_eventTarget().indexOf("sendMessage") != -1)
                 statusLabel.innerHTML = "Sending message...";
                else
                 statusLabel.innerHTML = "Restoring...";
            
             txtBody.disabled = true;
             sendMessage.disabled = true;        
             saveDraft.disabled = true;
                restoreDraft.disabled = true;
         }
            
         function OnResponseEnd(sender, args)
         {
         logEvent("OnResponseEnd fired");
             var txtBody = document.getElementById("<%= txtBody.ClientID %>");
             var sendMessage = document.getElementById("<%= sendMessage.ClientID %>");                 
             var saveDraft = document.getElementById("<%= saveDraft.ClientID %>");
             var restoreDraft = document.getElementById("<%= restoreDraft.ClientID %>");
            
             txtBody.disabled = false;
             saveDraft.disabled = false;
             sendMessage.disabled = false;
             restoreDraft.disabled = false;
         }
            </script>

        </telerik:RadCodeBlock>
        <!-- end of custom head section -->
    </head>
    <body class="BODY">
        <form runat="server" id="mainForm" method="post">
            <telerik:Header runat="server" ID="Header1" NavigationLanguage="CS" ShowSkinChooser="true">
            </telerik:Header>
            <!-- content start -->
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
            <telerik:RadFormDecorator ID="RadFormDecorator1" runat="Server" />
            <qsf:EventLogConsole runat="server" ID="EventLogConsole1" Style="float: right;" Width="140px"
                Height="351px" />
            <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" ClientEvents-OnResponseEnd="OnResponseEnd"
                ClientEvents-OnRequestStart="OnRequestStart">
                <div style="background: url(Img/bg.gif) no-repeat; width: 600px; height: 362px; padding-top: 24px;
                    text-align: center;">
    <asp:Button Text="Send Message" OnClick="sendMessage_Click" runat="server" ID="sendMessage"
    Style="width: 116px;"></asp:Button>

    <asp:Button Text="Save Draft" OnClick="saveDraft_Click" runat="server" ID="saveDraft"
    Style="width: 116px;"></asp:Button>

    <asp:Button Text="Restore Draft" OnClick="restoreDraft_Click" runat="server" ID="restoreDraft"
    Style="width: 116px;"></asp:Button>

                    <br />
                    <br />
                    <br />
                    <br />
                    <br />
                    <br />
    <asp:TextBox ID="txtBody" Text="Type here..." runat="server" Width="509px" Height="208px"
    TextMode="MultiLine" Rows="100" Columns="20" Style="border: 0px; background-color: transparent;
    font-size: 12px;"></asp:TextBox>

    <asp:Label ID="statusLabel" runat="server" Style="color: #698901; margin-top: 13px;
    display: block;"></asp:Label>

                </div>
            </telerik:RadAjaxPanel>
            <!-- content end -->
            <telerik:Footer runat="server" ID="Footer1"></telerik:Footer>
        </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