title: Downloading file clicking on Linkbutton asp.net
body: <p>I am trying to provide a linkbutton(asp) with a click function attached to it in c#. When the user clicks on the linkbutton the backend code sends a pdf file to the user for download.</p>
  
  <p>I have completed the code and it seems to download the file when the page is opened. But in one of my cases it opens the page as a windows dialog. </p>
  
  <p>In this case, When I click on the linkbutton the code executes but there is no download operations that happens. The download of the document fails when the same page is loaded inside the Window dialog that is opened using windows.open. </p>
  
  <p>Eg: Parent Page: Dashboard.aspx
      Child Page: DownloadFormatSelector.aspx
  I navigate to localhost/DownloadFormatSelector.aspx page and click on "Download" button the browser (IE) shows options to "Save As","Open". </p>
  
  <p>But if I open the DownloadFormatSelector.aspx page from dashboard using window.showModalDialog. The download does not happen
  Eg: localhost/Dashboard.aspx and DownloadFormatSelector.aspx page opens inside ot using window.showModalDialog.</p>
  
  <p>I am stuck why when the page is rendered inside a window.showModalDialog it does not download the document or display the Save as option.</p>
  
  <p>All the following codes are present in DownloadFormatSelector file.</p>
  
  <p>Dashboard.aspx is just the parent window. I am able to perform download when the child window is navigated to (Like localhost/DownloadFormatSelector.aspx) but the same page when opened inside a window.showModalDialog I am not able to download the file has the page does not display any save as or open options below. what can I modify to perform save on the page inside the showmodaldialog</p>
  
  <p>Code c# click:</p>
  
  <pre><code>public void DownloadButton_Click(Object sender, EventArgs e)
  {
      byte[] data=GetData();
      Response.Clear();
      Response.AddHeader("Content-Disposition",
      String.Format("attachment;filename={0}", "temp.pdf"));            
      Response.ContentType = "application/pdf";
      Response.BinaryWrite(data);
      Response.End();
  }
  </code></pre>
  
  <p>Asp.Net</p>
  
  <pre><code>&lt;asp:LinkButton id="Link" Text="Download" OnClick="DownloadButton_Click" runat="server"/&gt;
  </code></pre>
  
  <p>Open as window dialog : </p>
  
  <pre><code>window.showModalDialog JS method to call another aspx page to be rendered inside the dialog window
  </code></pre>