简体   繁体   English

Ajax UpdateProgress无法正常工作

[英]Ajax UpdateProgress not working

i am using ajax UpdateProgress bar in asp dot net with button click but query execute in write format but prrgress bar not run how to slove this type of problem.plz help me give me any solutions of progress bar 我在asp点网中使用ajax UpdateProgress栏并单击按钮,但是查询以写格式执行,但是prrgress栏无法运行以解决此类问题。请帮助我给我进度栏的任何解决方案

 <html xmlns="http://www.w3.org/1999/xhtml">
 <head runat="server">
 <title></title>
 <style type="text/css">
    .style1
    {
        width: 100%;
    }
 </style>
 <script language="javascript" type="text/javascript">
    var prm = Sys.WebForms.PageRequestManager.getInstance();

    prm.add_initializeRequest(InitializeRequest);
    prm.add_endRequest(EndRequest);
    var postBackElement;
    function InitializeRequest(sender, args) {

        if (prm.get_isInAsyncPostBack())
            args.set_cancel(true);
        postBackElement = args.get_postBackElement();
        if (postBackElement.id == 'Button1')
            $get('UpdateProgress1').style.display = 'block';
    }



    function EndRequest(sender, args) {
        if (postBackElement.id == 'Button1')
            $get('UpdateProgress1').style.display = 'none';
    }



 </script>
 </head>
 <body>
 <form id="form1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">  
   <ContentTemplate>  
  <asp:ToolkitScriptManager ID="ScriptManager1" runat="server">
       </asp:ToolkitScriptManager>

       <table class="style1">
           <tr>
               <td>
                   &nbsp;</td>
               <td>
                   <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
               </td>
               <td>
                   <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
               </td>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
           </tr>
           <tr>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
           </tr>
           <tr>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
           </tr>
           <tr>
               <td>
                   </td>
               <td>
                   </td>
               <td>
                   <asp:Button ID="Button1" runat="server" onclick="Button1_Click"Text="Button"/>
               </td>
               <td>
                   </td>
               <td>
                  </td>
               <td>
                       </td>
           </tr>
           <tr>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
               <td>

               </td>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
           </tr>
           <tr>
               <td>
                   &nbsp;</td>
               <td>
               </td>
               <td>
              </td>
               <td>
                 </td>
               <td>
                  </td>
               <td>
                 </td>
           </tr>
       </table>


  <asp:UpdateProgress ID="PageUpdateProgress" runat="server">
                        <ProgressTemplate>
                            <asp:UpdateProgress ID="UpdateProgress1" runat="server">
                                <ProgressTemplate>
                                 <img src="images/ajax-loader.gif" alt="image missing" />
                                </ProgressTemplate>
                            </asp:UpdateProgress>
                        </ProgressTemplate>
                    </asp:UpdateProgress>

  </ContentTemplate>
  </asp:UpdatePanel>
  </form>
  </body>
 </html>

I think you are missing a prm.add_beginRequest(onPrmBeginRequest); 我认为您缺少prm.add_beginRequest(onPrmBeginRequest); here. 这里。

The progress must be shown when the request begins: 请求开始时必须显示进度:

onPrmBeginRequest = function (sender, args) {
    var postBackElement = args.get_postBackElement();
    if (postBackElement.id == 'Button1') {
        $get('UpdateProgress1').style.display = 'block';
    }
}

So move the appropriate code block from initializeRequest to beginRequest . 因此,将适当的代码块从initializeRequest移到beginRequest

Now you can hide in endrequest . 现在您可以隐藏在endrequest

Note : 注意事项

The id may have been mangled by ASP.Net unless clientIDMode is specified. 除非指定了clientIDMode ,否则该id可能已经由ASP.Net处理。 So make sure you are using the id like ctl00_ContentPlaceHolder1_UpdateProgress1 . 因此,请确保您使用的idctl00_ContentPlaceHolder1_UpdateProgress1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM