Dzun Ho
Dzun Ho

Reputation: 367

Display message in a label before download popup shown?

I have a following code:

lblInfoMessage.Text = "Successful";

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.BufferOutput = false;
HttpContext.Current.Response.ContentType = "application/zip";
HttpContext.Current.Response.AddHeader(
     "content-disposition",
     string.Format("attachment; filename={0}", zipFileName));

// code to generate a file

HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();

And this page is only show a popup to download a file I generated but I also need a message shown in label lblInfoMessage.

Upvotes: 0

Views: 807

Answers (1)

Scotty
Scotty

Reputation: 1137

For your label to show the message, the page needs to post back first. You can only do a postback OR a file download, you can't do both in the one request.

Typically, websites that offer file downloads display a message like "your file will download in 10 seconds". After this time the page loads a different page which contains the code to download the file.

This can be achieved in asp.net by using a meta refresh tag which automatically redirects you from your "success" page to your 2nd page which contains your file download code.

Here's a good article showing how to use meta refresh in asp.net http://www.aspsnippets.com/Articles/Redirect-to-another-page-after-5-seconds-in-ASPNet.aspx

Upvotes: 1

Related Questions