I have an export button in my application.
When I click the button, it posts back to the server and generates an Excel file.
I want to show a loading gif during the process, but when the open/save dialog shows, I want to hide the gif.
The problem is that I use Response.End to display the file open/save dialog.
Does anyone knows how can I call a client side function after Response.End, or anyone has another solution how can I hide the gif and let the user work?
here is a piece of my code:
protected void Page_Load(object sender, EventArgs e)
{
//starts the loading gif animation.
btnExport.Attributes.Add("onclick", "setTimeout(\"UpdateImg();\",300);");
}
protected void btnExport_Click(object sender, EventArgs e)
{
//generates the file
Response.ContentType = "application/vnd.openxmlformats- officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment; filename=ExcelDemo.xlsx");
Response.BinaryWrite(pck.GetAsByteArray());
Response.Flush();
//Response.End();
HttpContext.Current.ApplicationInstance.CompleteRequest();
//HERE I WANT TO STOP THE ANIMATION AND GO BACK TO THE PAGE!
}
Thank you,
Inbal.
This way you can not do that.
When you start send your data to the file and open a save dialog, your web page have lost the control and you can not do anything any more, the data are all go to the file save.
What other and in my opinion better, options you have.
You can use a handler .ashx to create and send your file, and you give the link to your page with the parameters you need to make the file.