【问题标题】:ajax "loading" icon with UpdatePanel postbacks带有 UpdatePanel 回发的 ajax“加载”图标
【发布时间】:2011-02-18 07:21:57
【问题描述】:

我有一个使用 Ajax(内置 .NET Ajax 和 UpdatePanel)根据用户选择动态构建的表单。

如何在回发发生时插入“标准”ajax 加载图标(可能将其附加到鼠标指针上),然后在回发完成后将其删除?

如果有帮助,我确实安装了 AjaxToolKit。

【问题讨论】:

    标签: c# asp.net ajax updatepanel postback


    【解决方案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>
    

    http://loading.io/加载图片

    【讨论】:

      【解决方案2】:

      在这里我找到了一些 JavaScript 来自己进行更新过程,你也可以把它放在页面的任何地方,它可以在页面中的任何更新面板上工作。

      <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> 
      

      【讨论】:

      • 经过一些有限的测试后,我发现在使用框架的&lt;asp:updateprogress&gt; 控件时,动态添加DOM 元素会有一点延迟。相反,这种连接相关 JS 事件的方法提供了即时的 UI 反馈。
      • 是的,它的速度更快,但速度有点慢,但如果你的页面很重,并且有很多 dom,你可以区分两者的速度
      • 这很适合我的情况,因为我在一个区域有 3 到 7 个更新面板,如果有任何更新我想做一些“工作”,这让我可以聆听它们并显示和隐藏并根据需要操作 dom,谢谢!
      【解决方案3】:

      使用以下代码...

       <html xmlns="http://www.w3.org/1999/xhtml">
       <head runat="server">
           <title></title>
       </head>
       <body>
          <form id="form1" runat="server">
           <div>
               <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
          <asp:UpdateProgress ID="updProgress"
          AssociatedUpdatePanelID="UpdatePanel1"
          runat="server">
              <ProgressTemplate>            
              <img alt="progress" src="images/progress.gif"/>
                 Processing...            
              </ProgressTemplate>
          </asp:UpdateProgress>
      
          <asp:UpdatePanel ID="UpdatePanel1" runat="server">
              <ContentTemplate>
                  <asp:Label ID="lblText" runat="server" Text=""></asp:Label>
                  <br />
                  <asp:Button ID="btnInvoke" runat="server" Text="Click" 
                      onclick="btnInvoke_Click" />
              </ContentTemplate>
          </asp:UpdatePanel>         
            </div>
         </form>
        </body>
      </html>
      
      
      protected void btnInvoke_Click(object sender, EventArgs e)
      {
          System.Threading.Thread.Sleep(3000);
          lblText.Text = "Processing completed";
      }
      

      【讨论】:

        【解决方案4】:

        使用工具包的updateprogress:希望这对你有帮助

        <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>
        

        【讨论】:

          猜你喜欢
          • 2023-04-06
          • 1970-01-01
          • 2017-12-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-09-30
          相关资源
          最近更新 更多