title: ASP .NET Print iFrame
body: <p>I have an ASP .Net application that prints when a button is clicked. The application uses an iFrame to print. </p>
  
  <p>This is my Markup:</p>
  
  <pre><code>&lt;iframe id="ifPrint" clientidmode="static" runat="server" style="width:100%;height:1px;" /&gt;
  </code></pre>
  
  <p>This is my Javascript function that gets called to print the report:</p>
  
  <pre><code>function PrintReport() {
      window.frames["ifPrint"].focus();
      window.frames["ifPrint"].print();
  }
  </code></pre>
  
  <p>The button is in a page called <code>Search.aspx</code>. This is what happens when the print button is clicked:</p>
  
  <pre><code>ifPrint.Attributes["src"] = "~/Pages/PrintWeightTicket.aspx?wt=" + sWeightTicket;
  ScriptManager.RegisterStartupScript(this, this.GetType(), "PrintWeight", "PrintReport();", true);
  </code></pre>
  
  <p>As you can see, the button is supposed to set the source to the <code>PrintWeightTicket.aspx</code> page and print the contents of THAT page. But for some reason, when I hit print, it prints the current page. I put a breakpoint in my C# code and checked the value of <code>ifPrint.Src</code> and it was set correctly to the <code>PrintWeightTicket</code> page. But for some reason, when the function in the Javascript gets called, the src is just not taking effect. </p>
  
  <p><strong>Things I've tried:</strong>    </p>
  
  <ol>
  <li>I tried setting the iframe's source like this:<br>
  <code>ifprint.Src = "~/Pages/PrintWeightTicket.aspx?wt=" + sWeightTicket;</code><br>
  That did not do anything.</li>
  <li>I added this:<br>
  <code>Response.Redirect("~/Pages/PrintWeightTicket.aspx?wt=" + sWeightTicket, false);</code><br>
  Right below the <code>ScriptManager.RegisterStartupScript</code> line. It works if I do that! But, my boss tells me we don't want the page to redirect to the print page. We want the page to stay at Search page and the print dialog pops up and prints the redirect page. So I had to comment that out and now it does not work.</li>
  <li>I saw in a post on SO that I could try calling the <code>ScriptManager.RegisterStartupScript</code> function from <code>Page_PreRender()</code> function. When I do that, I get the print popup as soon as I open the main page. I don't want that. That actually would not even work because I need to enter the weight ticket ID to be able print anything. </li>
  </ol>
  
  <p>Anyone has any ideas as to why the <code>iFrame</code>'s src is not getting set?</p>
  
  <p>Thank you.</p>
  
  <p>P.S.:<br>
  The <code>ClientIDMode = "Static"</code> line in the markup needs to stay for reasons. If anyone thinks that is the reason why this does not work, I'll look into working around that. </p>
  
  <p><strong>EDIT 1:</strong><br>
  After a bit of testing, I found out that my current code works perfectly in Chrome. But it does not work in IE.</p>
  
  <p><strong>EDIT 2:</strong><br>
  My Javascript file is called <code>JS_Scripts.js</code>. I have a <code>AJS.JS</code> and a <code>AJS_fx.JS</code>. When I open Developer tools and run HTTP Watch (The green play button under network tab, not sure if that is what it is called), I notice that all three of my javascript files AND a <code>WebResource.axd?.....</code> file are getting a result of <code>(Aborted)</code>. Although, it does has a result of <code>200</code> in Chrome. IE is not completing the execution of the scripts for some reason.</p>