15

I have a form that is being dynamically built depending on user selection using Ajax (built in .NET Ajax with UpdatePanel).

how can I insert a "standard" ajax loading icon (maybe have it attached to the mouse pointer) while the postback is happening then remove it when the post back is finished?

I do have the AjaxToolKit installed if that helps.

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
Kyle
  • 10,839
  • 17
  • 53
  • 63

3 Answers3

42

use updateprogress of tool kit :hope this will help you

<asp:updatepanel id="ResultsUpdatePanel" runat="server">    
<contenttemplate>

<div style="text-align:center;">
    <asp:updateprogress id="UpdateProgress1" runat="server" associatedupdatepanelid="ResultsUpdatePanel" dynamiclayout="true">
                        <progresstemplate>

                           <img src="support/images/loading.gif">

                        </progresstemplate>
                    </asp:updateprogress>

                    </div>

 //your control code
</contenttemplate>
</asp:updatepanel>
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
4

I found some JavaScript in this article, 3 Different Ways to Display Progress in an ASP.NET AJAX Application by Suprotim Agarwal to make update process yourself and also you can put it anywhere in page and it work any update panel in page .

    <script type="text/javascript">
                 // Get the instance of PageRequestManager.
                 var prm = Sys.WebForms.PageRequestManager.getInstance();
                 // Add initializeRequest and endRequest
                 prm.add_initializeRequest(prm_InitializeRequest);
                 prm.add_endRequest(prm_EndRequest);
                
                 // Called when async postback begins
                 function prm_InitializeRequest(sender, args) {
                     // get the divImage and set it to visible
                     var panelProg = $get('divImage');                
                     panelProg.style.display = '';
                     // reset label text
                     var lbl = $get('<%= this.lblText.ClientID %>');
                     lbl.innerHTML = '';
     
                     // Disable button that caused a postback
                     $get(args._postBackElement.id).disabled = true;
                 }
     
                 // Called when async postback ends
                 function prm_EndRequest(sender, args) {
                     // get the divImage and hide it again
                         $('divImage').hide();                
                      // Enable button that caused a postback
                     $get(sender._postBackSettings.sourceElement.id).disabled = false;
                 }
             </script>
blackgreen
  • 34,072
  • 23
  • 111
  • 129
Anant Dabhi
  • 10,864
  • 3
  • 31
  • 49
  • After some limited testing I found there to be a slight delay in the dynamic addition of DOM elements when using the framework's `` control. Contrarily this method of hooking up the relevant JS events gave instant UI feedback. – Red Taz Oct 05 '12 at 07:33
  • yes its a faster but little bit but if you have a heavy page with lots of dom you can differentiate speeds of both – Anant Dabhi Oct 05 '12 at 11:16
1
<asp:UpdateProgress ID="updateProgress" runat="server">
            <ProgressTemplate>
                <div class="loading-panel">
                    <div class="loading-container">
                        <img src="<%= this.ResolveUrl("~/images/gears.gif")%>" />
                    </div>
                </div>
            </ProgressTemplate>
        </asp:UpdateProgress>
        <style>
            .loading-panel {
                background: rgba(0, 0, 0, 0.2) none repeat scroll 0 0;
                position: relative;
                width: 100%;
            }

            .loading-container {
                background: rgba(49, 133, 156, 0.4) none repeat scroll 0 0;
                color: #fff;
                font-size: 90px;
                height: 100%;
                left: 0;
                padding-top: 15%;
                position: fixed;
                text-align: center;
                top: 0;
                width: 100%;
                z-index: 999999;
            }
        </style>

Loading images from:http://loading.io/

OldTrain
  • 1,880
  • 1
  • 25
  • 22