ModalPopupExtender won't hide after Response.fush,respose.end()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chandramohan089
    New Member
    • Aug 2011
    • 3

    ModalPopupExtender won't hide after Response.fush,respose.end()

    Hi,

    I have a modal popup with two radio-buttons as Excel and CSV and two buttons as download and cancel

    On clicking download button i am doing the download functionality using response object.

    I am trying to close the modal popup after downloading.usi ng modalpopuExtend er.hide()

    But the modal popup is not hiding.

    DESIGN:
    Code:
    <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" X="600" Y="250" TargetControlID="HiddenField1" PopupControlID="Panel1" 
                         CancelControlID="btnCancel" >
                        </cc1:ModalPopupExtender>
                        <asp:HiddenField ID="HiddenField1" runat="server" />
                        <asp:Panel ID="Panel1" runat="server" width="250px" height="150px" Style="display: none;">
                            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                                <ContentTemplate>
                                    <table cellspacing="2" cellpadding="2" width="350px" height="100px" style="border:1px solid black;" bgcolor="#eeeeee" >
                                        <tr>
                                            <td align="right">
                                                Select File Type:
                                            </td>
                                            <td >
                                                <asp:RadioButtonList ID="rblFileType" runat="server" RepeatDirection="Horizontal">
                                                    <asp:ListItem Text="Excel" Value="Excel"></asp:ListItem>
                                                    <asp:ListItem Text="CSV" Value="CSV"></asp:ListItem>
                                                </asp:RadioButtonList>
                                            </td>
                                            
                                        </tr>
                                        <tr>
                                            <td align="right">
                                                
                                            </td>
                                            <td align="left">
                                                <asp:Button ID="btnDownload" runat="server" Text="Download"  CssClass="button" 
                                                    onclick="btnDownload_Click" />
                                                <asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="button" 
                                                    onclick="btnCancel_Click"/>
                                            </td>
                                        </tr>
                                    </table>
                                </ContentTemplate>
                                <Triggers>
                                    <asp:PostBackTrigger ControlID="btnDownload" />
                                </Triggers> 
                            </asp:UpdatePanel>
                        </asp:Panel>
                    </td>
    Code Behind:
    Code:
     protected void btnDownload_Click(object sender, EventArgs e)
        {
            
            if (rblFileType.Items[0].Selected == true)
            {
                Response.Clear();
                Response.Charset = "";
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AppendHeader("Content-Disposition", "attachment; filename=Organization.xlsx");
                Response.TransmitFile(Server.MapPath("~/Upload_Files/Templates/Organization.xlsx"));
                Response.Flush();
                Response.End();
            }
            else
            {
                Response.Clear();
                Response.Charset = "";
                Response.ContentType = "csv";
                Response.AppendHeader("Content-Disposition", "attachment; filename=Organization.csv");
                Response.TransmitFile(Server.MapPath("~/Upload_Files/Templates/Organization.csv"));
                Response.Flush();
                Response.End();
            }
    
            ModalPopupExtender1.Hide();
            UpdatePanel1.Update();
        }
    Please let me know what is the problem with my code.

    Thank you .

    Chandramohan
    Last edited by Frinavale; Jan 18 '12, 04:18 PM. Reason: Fixed code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    I have a feeling that you're going to have to go about this a bit differently. I haven't been able to successfully retrieve a file the way you are attempting....

    Move the logic for retrieving the file into it's own ASPX page. The purpose of the page is to simply retrieve what the user requests.

    Add an IFrame to your page and when you click the btnDownload, call some JavaScript that sets the source of the IFrame to the URL of the ASPX page that retrieves the file.

    If they hit cancel, then call some JavaScript that hides the popup.

    -Frinny

    Comment

    Working...