Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page Refresh in ASP.NET

Tags:

c#

asp.net

save dialog saves file to the local machine. But after that, my page stand there and do nothing for the rest of my process. I use below code to open a save dialog

protected void lnkbtnDownload_Click(object sender, EventArgs e)
{
  string fileName = startupPath + "bin\\Inbox.mdb";
  System.IO.FileInfo targetFile = new System.IO.FileInfo(fileName);

  if (targetFile.Exists)
  {
      Response.Clear();
      Response.AddHeader("Content-Disposition", "attachment; filename=" + targetFile.Name);
      Response.AddHeader("Content-Length", targetFile.Length.ToString());
      Response.ContentType = "application/octet-stream";
      Response.WriteFile(targetFile.FullName);                        
      Response.End();
  }
}

the html code is :

<asp:Button id="lnkbtnDownload" runat="server" CausesValidation="false" 
  Text="Download" CssClass="buttonstyle"  OnClick="lnkbtnDownload_Click"></asp:Button>

but after the file is save to local machine and the save dialog is close, my page no response at all. May I know how to do a postback to the page after the save dialog is close.?

like image 947
Guddu Avatar asked Mar 09 '26 15:03

Guddu


1 Answers

Because you are calling Response.End, this halts the response of the page.

like image 196
Andrew Corkery Avatar answered Mar 12 '26 06:03

Andrew Corkery