Last post Apr 15, 2008 05:26 PM by KevinAMac
Apr 15, 2008 03:34 PM|KevinAMac|LINK
I am using a querystring to pass in the name of a PDF document to a form containing an <iframe> control in which I am going to display the PDF. Since I can't modify the src attribute directly in code, I tried this code adapted from a VB example I found on
pdfFrame = (
When I run this I get a null exception on the variable pdfFrame. Can someone please tell me what I am doing wrong? I am thinking there is something wrong with the way I am casting the variable pdfFrame -- the VB example defined it as HtmlGenericControl but
I got a conversion error when I tried to assign the reference to the <iframe> control to this variable.
Apr 15, 2008 03:57 PM|Ken Tucker|LINK
Apr 15, 2008 04:54 PM|KevinAMac|LINK
Yes, it is set as runat="server"
Apr 15, 2008 05:15 PM|Ken Tucker|LINK
If it is runat="server" you do not have to find the control
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /></div>
<iframe id="pdfFrame" src="http://msdn.microsoft.com" runat="server" />
protected void Button1_Click(object sender, EventArgs e)
pdfFrame.Attributes["src"] = "http://www.asp.net";
Apr 15, 2008 05:20 PM|KevinAMac|LINK
OK, I have been messing around with it and here is the latest:
If I use the above code in a normal form to display the PDF, it works just fine and displays the PDF.
However, I wanted to display the PDF in a page using a Master Page. The <iframe> is part of the web content page. Apparently, findcontrol doesn't work on a web content page. Is there something else that does work?
Thanks for all of you help!
Apr 15, 2008 05:26 PM|KevinAMac|LINK
Exactly right! I think I got my wires crossed because the references I was looking at online were dealing with controls located in the master page content instead of the web content form.
Thanks very much for clearing this up!