views:

25

answers:

0

I want to open a PDF file after clicking a button within gridview, which is inside an updatepanel.

Using Response.Write() etc. requires full postaback to send the HTTP headers for the file. I dont want to use a postback trigger on my gridview, so after going through some forums I decided to use javascript and the hidden iframe trick to run the file-opening code within that iframe.

The problem, or annoyance, is that when I click on the button to open the file, IE gives me a "Download File Warning" at the top of the browser. Is there anyway for me to avoid getting this warning while not doing a full postback on my main page.

Javascript Code:




  function open (fileLocation)
     // Create an IFRAME.
      var iframe = document.createElement("iframe");

      // Get the desired region from the dropdown.


      // Point the IFRAME to PDF, with the
      //   desired file as a querystring argument.
      iframe.src = "PDF.aspx?file=" + fileLocation;

      // This makes the IFRAME invisible to the user.
      iframe.style.display = "none";

      // Add the IFRAME to the page.  This will trigger
      //   a request to PDF now.
      document.body.appendChild(iframe); 
   }

 

ButtonClick code:


private void button1_Click(object sender, EventArgs e) 

{ 


   ScriptManager.RegisterStartupScript(this, GetType(), "open", "open('blah.pdf')", true);


}