ModalPopupExtender conflict with download file via Response.BinaryWrite RRS feed

  • Question

  • User-86041214 posted

    Dear All:

    I meet an big problem and can not fix it. While I use Response.BinaryWrite to download file directly, then 

    the ModalPopupExtender become useless, that means when I click button , the UI not showing any thing about

    ModalPopupExtender panel.

    The Response.BinaryWrite code snippet is following:

    <asp:UpdatePanel ID="uppnlDownloadFile" runat="server" UpdateMode="Always">
    <asp:PostBackTrigger ControlID="btntest" />
    string filename = "tt.xls"; Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", filename)); Response.Clear(); using (HSSFWorkbook wb1 = new HSSFWorkbook()) { Response.BinaryWrite(WriteToStream(ReadDataTableToExcel(dt, sheetName, 1000)).GetBuffer()); } Response.End();

    And the use of modalpopupentendar is as following:

    <asp:Button ID="btnDummy" runat="server" Style="visibility: hidden" />
    	<cc3:ModalPopupExtender ID="ModalPopupExtenderCodeHandling" runat="server"

    Is any way to solve that, thanks a lot.

    Thursday, June 16, 2016 7:41 AM

All replies

  • User61956409 posted

    Hi abramhum.c.l,

    According to your description and code, it seems that you’d like to show modal popup that displays “CodeHandling”, if that is the case, you could try to show ModalPopupExtender control via JavaScript.

        function showmodal() {
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" OnClientClick="showmodal();" />
        <asp:Button ID="btnDummy" runat="server" Style="visibility: hidden" />
        <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
        <asp:Panel ID="upnlCodeHandling" runat="server">
    protected void Button1_Click(object sender, EventArgs e)
        System.IO.FileStream fs = null;
        fs = System.IO.File.Open(Server.MapPath("MyText.txt"), System.IO.FileMode.Open);
        byte[] btFile = new byte[fs.Length];
        fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
        Response.AddHeader("Content-disposition", "attachment; filename=hello.txt");
        Response.ContentType = "application/octet-stream";

    Best Regards,

    Fei Han

    Friday, June 17, 2016 7:38 AM
  • User-86041214 posted

    After testing,  the modalPopupExtenderCodeHandling will become null after ouput the xls file.

    Is there any other way to solve the problem, thanks

    Monday, June 20, 2016 3:12 AM
  • User61956409 posted

    Hi abramhum.c.l,

    After testing,  the modalPopupExtenderCodeHandling will become null after ouput the xls file.

    We specify BehaviorID="modalPopupExtenderCodeHandling" then find the ModalPopupExtender control via BehaviorID by using JavaScript, you said the modalPopupExtenderCodeHandling becomes null after you download the xls file, do you mean ModalPopupExtender control disappears?

    Best Regards,

    Fei Han

    Thursday, June 23, 2016 9:40 AM
  • User-86041214 posted

    I don't know, but if i use javascritp to get the element by id, then it return null. I use updatepanel with the button to invoke 

    download file event. and another button to invoke modalpopupextender. modalpopupextender will become null after response.End(); 

    However, if I don't use updatepanel, then , after post back, modalpopupextender will work well.

    It seems when I use response.End() under the upatepanel, the browser will clean all the instance of ajaxcontroltoolkit, until reload the 

    page. I still can not find any way to cover that. And also, I don't know how to find any book about the construction of akaxcontroltoolkit and 

    browser. The books just told us how to use it. not telling us why and how to create it. And what the browser and jquery cooperator.  And that 

    makes it hard to fix by writing other codes. Thanks. 

    Friday, June 24, 2016 5:52 AM