0

I have a button who does the following:

Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.csv");
Response.Charset = "";
Response.ContentType = "application/text";
//my content is created
Response.Output.Write(sb.ToString());
Response.Flush();
Response.End();

This is my button definition:

<asp:Button ID="Button1" runat="server" onclick="Excel_Click" Text="Export to Csv" onclientclick="ShowModal();"/>

As you can see I call a javascript function, who does the following:

function ShowModal() {
        var divmodal = document.getElementById("divModal");

        divmodal.style.display = '';
    }

i.e. shows a modal window with the label "Loading" My problem is when I download the file I get the csv generated but after that my modal window still appears, that's because the page isn't being refreshed

Is there anything I can do?

Thanks in advance

Naty Bizz
  • 2,262
  • 6
  • 33
  • 52

1 Answers1

2

The short answer is that you can not do that.

After your post back with the button the page that you are is waiting a new content to load. At this moment you do not have any control to the current page dom from the code behind, eg send them a javascript code to execute.

Even if you do send a full page back, then its a new full page.

You can make some other trick, eg use a handler to download the file and a link, or use ajax to send the command, and again return with a link to a handler - but that way, with a full post back, you can not do that.

Aristos
  • 66,005
  • 16
  • 114
  • 150