0

In my ASP.NET Web Forms application, I have to download a string as a file right after i'm doing an action on the web page. The flow is as follows:

  1. Do initial action (button click)
  2. It opens up a popup window where the username and password are required.
  3. Fill in the username and password
  4. Do second action (button click inside popup)

Now, after the second action is done, I want my page to reload and start downloading my string as a file.

If I write my string in the response like below, the file gets downloaded, but the pop-up window does not close.

Response.Write(mystring);

I tried these ways:

  1. Context.Response.Clear();
    Response.AddHeader("Content-Disposition", "inline; filename=Warrants.warrant");
    Response.ContentType = "application/lsw_print";
    Response.ContentEncoding = System.Text.Encoding.UTF8;
    Response.Write(mystring);
    Response.Flush();
    Response.End();
    
  2. 2.
Context.Response.Clear();
Response.AddHeader("Content-Disposition", "inline; filename=Warrants.warrant");
Response.ContentType = "application/lsw_print";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Write(mystring);
Response.Flush();
ApplicationInstance.CompleteRequest();
  1. Context.Response.Clear();
    Response.AddHeader("Content-Disposition", "inline; filename=Warrants.warrant");
    Response.ContentType = "application/lsw_print";
    Response.ContentEncoding = System.Text.Encoding.UTF8;
    Response.Write(mystring);
    

All these versions download my file, but ends the requests and my pop-up doesn't get closed.

Also, the popup I use is a control having an iframe in it.

Thanks!

Frody
  • 163
  • 10
  • Isn't it possible to store the string content to viewstate or session on second action click, then start downloading it after pop-up was closed and page was rendered ? – KMarron Apr 09 '20 at 15:07
  • @KMarron your suggestion is to download using Response.Write or you suggest other way to do it? Also, what would be the method in which I should call the download? – Frody Apr 10 '20 at 06:29
  • No need to use Response.Write. IMHO, store the string in Session/Viewstate (or HiddenField). Do second action. Close the pop-up and postback page. Then start downloading with the string stored where you put it before postback. – KMarron Apr 10 '20 at 12:06

0 Answers0