Can anybody help me? I am following instructions about how to put an Iframe in my app.
Here is the code for the button:
protected void Submit_Click(object sender, EventArgs e)
{
//frame1 = (HtmlGenericControl)this.FindControl("frame1");
HtmlControl frame1 = (HtmlControl)this.FindControl("frame1");
frame1.Attributes["frameborder"] = "0";
frame1.Attributes["scrolling"] = "auto";
frame1.Attributes["width"] = 640 + "px";
frame1.Attributes["height"] = 500 + "px";
frame1.Attributes["marginheight"] = "0";
frame1.Attributes["marginwidth"] = "0";
frame1.Attributes["src"] = "https://www.google.com/a/speednet.com/LoginAction2?service=mail";
}
Here is the html:
<iframe id="frame1" scrolling="auto" runat="server">
</iframe>
The problem is pretty simple actually. The line of code:
HtmlControl frame1 = (HtmlControl)this.FindControl("frame1");
returns a null object for frame1.
So I get the error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 27: frame1.Attributes["frameborder"] = "0";
The first line I try to access the Attributes of the frame1 object (which is somehow null after the FindControl didn't find the Control????
Please help