Post-back after file download does not work

那年仲夏 提交于 2020-01-25 10:03:49

问题


My page has a pop-up. The button on popup generates and downloads Aspose excel file. (The page also has Ajax settings)

Now after file download, my button is disabled and nothing else works on page unless i refresh it manually.

Popup on page

<div class="modal hide" id="AwaitPracSignoffReportModal">
    <div class="modal-header">
        <a class="close" data-dismiss="modal">×</a>
        <h3>
            <asp:Label runat="server" ID="lblPopupHeading" Text="Awaiting Practice Sign-off Report" /></h3>
    </div>
   <!-- Other asp controls in popup-->

    <div class="modal-footer" style="margin-bottom: 5px">
        <button class="btn" data-dismiss="modal">
            Cancel</button>
        <asp:Button runat="server" ID="btnGenerateReport" CssClass="btn btn-primary"
            Text="Generate Report" ValidationGroup="ReportModal" OnClientClick="javascript:setFormSubmitToFalse();" />
    </div>

</div>

Script

function HideGenerateReportPopup() {
            $('#AwaitPracSignoffReportModal').modal().hide();
        }

        function setFormSubmitToFalse() {
            setTimeout(function () { _spFormOnSubmitCalled = false; }, 3000);
            return true;
        }

CodeBehind

btnGenerateReport.Click += (s, ev) =>
        {
            this.Presenter.ExportToExcel();

            ScriptManager.RegisterStartupScript(this, this.GetType(), "Generate Report", "HideGenerateReportPopup();", true);
        };

Presenter Code (different project)

 Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook();
        int worksheetNo = 0;

        foreach (System.Data.DataTable dt in ds.Tables)
        {
            Aspose.Cells.Worksheet worksheet = workbook.Worksheets[worksheetNo];

            worksheet.Cells.ImportDataTable(dt, true, "A1");
            worksheet.AutoFitColumns();
            worksheetNo++;
        }

        workbook.Save(HttpContext.Current.Response, filename, ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));

            HttpContext.Current.Response.Flush();
        HttpContext.Current.Response.End();

I have added setFormSubmitToFalse function as recommended here. If I try to add AjaxSettings for the btnGenerateReport, it gives script error

Uncaught Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

When i remove it, the page stays as is and no more contols work.


回答1:


Found my answer here

the page and the PDF. You can't do that. Typically download pages start a download as a separate request when you've gone to them (via JavaScript, I believe), with a direct link just in case the JavaScript doesn't work.

Now i have added a separte page (ashx) and open it in a separate tab.



来源:https://stackoverflow.com/questions/50575360/post-back-after-file-download-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!