New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Client-side Events

Event log

This example illustrates how to use the client-side API of RadAjaxManager 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 OnRequestStart is used to disable controls on the form and the display of status information. Moreover, using the OnRequestStart will 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. This example uses the OnResponseEnd event to update status information and re-enable form controls to allow the user to continue work.

  • DefaultCS.aspx
  • DefaultCS.aspx.cs
  • scripts.js
  • styles.css
<%@ Page Language="c#" CodeFile="DefaultCS.aspx.cs" AutoEventWireup="false" Inherits="Telerik.AjaxManager.ClientSideProgramming.ClientEvents.DefaultCS" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
    <link href="styles.css" rel="stylesheet" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <div class="demo-container size-medium no-bg">
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript" src="scripts.js"></script>
        </telerik:RadCodeBlock>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <ClientEvents OnResponseEnd="OnResponseEnd" OnRequestStart="OnRequestStart"></ClientEvents>
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="saveDraft">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="statusLabel"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="sendMessage">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="statusLabel"></telerik:AjaxUpdatedControl>
                        <telerik:AjaxUpdatedControl ControlID="txtBody"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="restoreDraft">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="statusLabel"></telerik:AjaxUpdatedControl>
                        <telerik:AjaxUpdatedControl ControlID="txtBody"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>

        <div class="messageContainer">
            <div id="buttonsContainer">
                <telerik:RadButton RenderMode="Lightweight" Text="Send Message" OnClick="sendMessage_Click" runat="server" ID="sendMessage" Skin="Silk"></telerik:RadButton>
                <telerik:RadButton RenderMode="Lightweight" Text="Save Draft" OnClick="saveDraft_Click" runat="server" ID="saveDraft" Skin="Silk"></telerik:RadButton>
                <telerik:RadButton RenderMode="Lightweight" Text="Restore Draft" OnClick="restoreDraft_Click" runat="server" ID="restoreDraft" Skin="Silk"></telerik:RadButton>
            </div>
            <telerik:RadTextBox RenderMode="Lightweight" ID="txtBody" Text="Type here..." runat="server" CssClass="messageContent" Resize="None" TextMode="MultiLine" Rows="100" Columns="20" Skin="Default"></telerik:RadTextBox>
            <asp:Label ID="statusLabel" runat="server" CssClass="status"></asp:Label>
        </div>
    </div>
    <qsf:EventLogConsole runat="server" ID="EventLogConsole1"></qsf:EventLogConsole>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance