Search code examples
c#asp.netajaxupdatepanelupdateprogress

Response.Redirect inside Update Panel While Using Update Progress C#.NET


I have a web application that uses ajax with asp.net and C#. Now I'm trying to export a report viewer from CodeBehind (page name is original.aspx) as a PDF file when clicking on an ASP button. Everything works perfect except when I put the button within UpdatePanel. So after searching the internet, I found that Response.BinaryWrite, Response.Flush and so on don't work with UpdanePanel unless if I specify the button as a PostBackTrigger which then neglects with the purpose of using the UpdatePanel because the page have many controls and so many steps going on before reaching the export step.

So I transferred the code for exporting to PDF to the Page Load event on another page (lets say Default.aspx) and thought to use Response.Redirect to open a new tab for the exporting page.

What really happened is that the PDF is downloaded automatically (While still being in the original Page (original.aspx)) and without redirection - Which is fine - but the UpdateProgress was activated and never stopped showing the gif picture. Just keep on looping. When removing the UpdateProgress from the code everything runs as expected. File is exported and downloaded while the button being inside the UpdatePanel (async not PostBackTrigger) and using the Response.Redirect from the CodeBehind.

Is there any solution for disabling, killing the UpdateProgress process from code behind with only a particular click even or any other solution for this issue?


Solution

  • You can set control's ID inside PostBackTrigger to postback full page instead of partial page update which causes file download issue.

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        ...
       <Triggers>
          <asp:PostBackTrigger ControlID="DownloadButton" />
       </Triggers>
    </asp:UpdatePanel>