Changing cursor over grid during AJAX callback

Thread is closed for posting
2 posts, 0 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 12 Feb 2007 Link to this post

    Requirements

    r.a.d.controls version

    2006 Q4 SP1
    Web.UI version 2007.3.1425
    .NET version

    2.0
    Visual Studio version

    2005
    programming language

    HTML, Javascript, CSS
    browser support

    all browsers supported by r.a.d.controls


     
  2. PROJECT DESCRIPTION
    There are cases when the developer would prefer not to use loading panel or loading template but still indicate somehow the user that there is an AJAX request currently being processed. One way to have such indication is changing the mouse cursor to "hourglass". This can be achieved by using AJAX Manager's client events RequestStart and ResponseEnd.

    The most straightforward way can be to set document.body.style.cursor = "wait". However, this setting might be overridden by the grid skinning mechanism. Therefore, additional CSS classes are used. The classes are empty by default but are overridden with specific selectors in order to change the cursor for all elements rendered in the grid.  On RequestStart the cursor is set to "wait". On ResponseEnd the class is replaced by an empty one, so the default settings are applied back.

    <style type="text/css"
    .Normal 
    .Wait 
    /* override grid cursors with a more specific CSS selector */ 
    .Normal TABLE 
    }  
    .Wait TABLE 
        cursor: wait; 
    .Normal Input 
    .Wait INPUT 
        cursor: wait; 
    .Normal a 
    .Wait a 
        cursor: wait; 
    </style> 

    Styles are applied on the div, that contains the grid.

        <script type="text/javascript"
         function RequestStart(sender, args)             
            {                
               var div = document.getElementById("<%=div1.ClientID%>");                  
               div.className = "Wait"
                       div.style.cursor = "wait"
                }            
         function ResponseEnd(sender, args)              
            {                
               var div = document.getElementById("<%=div1.ClientID%>");                  
               div.className = "Normal"
                       div.style.cursor = "default";             
            } 
        </script>  


    AJAX Manager's client event are used:
                <radA:RadAjaxManager ID="RadAjaxManager1" runat="server"
                    <AjaxSettings> 
                        <radA:AjaxSetting AjaxControlID="RadGrid1"
                            <UpdatedControls> 
                                <radA:AjaxUpdatedControl ControlID="RadGrid1"></radA:AjaxUpdatedControl> 
                            </UpdatedControls> 
                        </radA:AjaxSetting> 
                    </AjaxSettings> 
                    <ClientEvents OnRequestStart="RequestStart" OnResponseEnd="ResponseEnd" /> 
                </radA:RadAjaxManager> 

    The grid here is used just for illustrating purpose. The technique shown is applicable for much wider range of cases.
  • 23C72464-8FC9-43C3-9A12-B431B37B7758
    23C72464-8FC9-43C3-9A12-B431B37B7758 avatar
    11 posts
    Member since:
    Dec 2013

    Posted 10 Mar 2008 Link to this post

    Hello,

    Here is how to achieve the described functionality with RadControls for ASP.NET AJAX.

    Instead of the RadGrid wrapper element, any HTML element can be used to set the "wait" CSS class to.


    <%@ Page Language="C#" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
     
    <script runat="server">
     
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                System.Threading.Thread.Sleep(5000);
            }
        }
     
    </script>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     
    <head runat="server">
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <title>RadControls</title>
    <style type="text/css">
     
    .wait,
    .wait *
    {
        cursor:wait !important;
    }
     
    </style>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
     
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
     
    function showHourGlass(sender, args)
    {
        Sys.UI.DomElement.addCssClass($get("<%= RadGrid1.ClientID %>"), "wait");
    }
     
    function hideHourGlass(sender, args)
    {
        Sys.UI.DomElement.removeCssClass($get("<%= RadGrid1.ClientID %>"), "wait");
    }
     
    </script>
    </telerik:RadCodeBlock>
     
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <ClientEvents OnRequestStart="showHourGlass" OnResponseEnd="hideHourGlass" />
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
     
    <telerik:RadGrid
        ID="RadGrid1"
        runat="server"
        Width="800px"
        Skin="Vista"
        AllowSorting="true"
        DataSourceID="RadGridDataSource">
            <MasterTableView CommandItemDisplay="Top" />
    </telerik:RadGrid>
     
    <asp:XmlDataSource ID="RadGridDataSource" runat="server">
    <Data>
    <nodes>
    <node ID="1" Name="Name 1" Description="Description 1" />
    <node ID="2" Name="Name 2" Description="Description 2" />
    <node ID="3" Name="Name 3" Description="Description 3" />
    <node ID="4" Name="Name 4" Description="Description 4" />
    </nodes>
    </Data>
    </asp:XmlDataSource>
     
    </form>
    </body>
    </html>


    Regards,
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  • Back to Top

    This Code Library is part of the product documentation and subject to the respective product license agreement.