Execute code after CompleteRequest()

Posted by Sharpcnet under C# on 9/24/2014 | Points: 10 | Views : 743 | Status : [Member] | Replies : 1
I have to execute some more code after downloading a file, but itsn't happening. The compiler hits `ClearControls();` after `DownloadFile();`, but the function is not executed.
On the page I get the prompt to open or save the file. But the textboxes are not cleared.
What should be done in this case.

protected void btnOk_Click(object sender, EventArgs e)
{
//ClearControls(); // not working here too.
DownloadFile();
ClearControls();
}

private void DownloadFile()
{
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition","attachment;filename="+sName+".pdf");
Response.TransmitFile(Server.MapPath("~/documents/ready/" + strPdfName));
//Response.End();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}

private void ClearControls()
{
txtOne.Text="";
txtTwo.Text="";
}





Responses

Posted by: Naveenhcl on: 9/24/2014 [Member] Starter | Points: 25

Up
0
Down
Hi,

Once you call the CompleteRequest method the server function will stop so you can't able to continue after this. To overcome this you need to download the file by using new page and wrote download code part on pageload event of that new page and then close that once download a file, by following this you can able to continue the rest of code part.

Hope you get my point....

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response