How to Load a PDF File in Iframe in ASP.NET

Written by lysis
  • Share
  • Tweet
  • Share
  • Email

PDF files are a standard method in disseminating information on a website. PDF files lock the document from being edited to allow website owners the ability to provide documentation without any changes. An iframe is a way for website owners to display a PDF file within a webpage without the browser opening a full PDF window. This can be accomplished using .NET and C#.

Skill level:

Other People Are Reading


  1. 1

    Upload the PDF file to a directory on the web host. You need to take note of the location of the PDF file, because it's used in the settings for the iframe.

  2. 2

    Add the iframe to your ASP.NET web page. An iframe is similar to a "page within a page," so you need to place the iframe in a position where readers can easily see the PDF file. Below is the code for an iframe: <iframe runat="server" id="myPDF" src=""></iframe> The "temporaryfile.htm" is used as a placeholder for the iframe. It's replaced during start-up of the web page.

  3. 3

    Add the C# code to the page_load function in the code behind file of the .NET web page. To access the page_load function, right-click the file in your Visual Studio .NET workspace and select "View Code" from the menu. This will bring you to the function that runs every time the web page is loaded. Within this function, add the following code: myPDF.Attributes.Add("src", "<location_of_pdf>"); The "<location_of_pdf>" should be replaced with the URL of the PDF file uploaded at step 1.

  4. 4

    Test the web page by opening a web browser and navigating to the web page. The PDF should load into the iframe when the web page loads.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.