简体   繁体   中英

How to use update progress inside update panel, when the button executing code is outside update panel

I have a update panel, and a update progress inside it. I have moved the button outside update panel because, response.write was not working when I had the button inside the update panel. Now after moving the button outside the response.write is working but update progress is not. How can I make it to work when I have the button outside.

 <asp:UpdateProgress ID="UpdateProgress2" runat="server">     
 <ProgressTemplate>      
  <div style="width: 338px; position: relative; top: -420px; left: 80px" class="">          <b>Please Wait...</b>        
    <img runat="server" id="ajaxLoader" style="background-color: White; width: 338px;"                                 src="styles/images/loadImage.gif" alt="loading" />     
    </div>          </ProgressTemplate>         </asp:UpdateProgress>            
      </ContentTemplate>     </asp:UpdatePanel>     
      <asp:Button ID="btn_upload"  runat="server" Text="Upload"                             OnClick="upload_Click" /> 

Use trigger for your update panel

<asp:UpdatePanel>

.... content ... 

    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btn_upload" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>

1.) Response.Write does not work inside UpdatePanel by design (see why here: https://stackoverflow.com/a/3878111/1288619 ) - and by default UpdatePanel is automatically triggered by all of its children controls.

2.) When you place the button outside of it, you are triggering full postback and not the UpdatePanel 's partial rendering - so no update progress.

When you just register the button as an AsyncPostBackTrigger (where ever it may be) - you get the exact same situation as in the first case.

If you register the button as a (Full) PostBackTrigger , or set UpdatePanel 's rendering to be conditional and not triggered by its children - then you just get the exact same situation as in the second case.

So, do as alexsuslin suggests, simply change the text property of some Literal control inside UpdatePanel to what you would put in Response.Write (and set the button's visible property to false if you don't want it shown anymore - but do register it as AsyncPostBackTrigger if moved outside).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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