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 = '';
}
ie 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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.