IFRAME - loading pages dynamically - Thea Burger's Blog

Thea Burger's Blog

Wouldn't you like to know...

News

Photo's!!!

About me

I'm Reading: General Blogs

I'm Reading: Technical Blogs

IFRAME - loading pages dynamically

I wanted to load pages dynamically into an IFRAME, but then I realised that you can't access the src attribute from code-behind, not even if you add runat=server... Here is the solution:

1. Add runat=server to the IFRAME.

2. In the declarations section declare a HtmlGenericControl
    protected System.Web.UI.HtmlControls.HtmlGenericControl frame1;

3. Find your IFRAME :)
    HtmlControl frame1 = (HtmlControl)this.FindControl("frame1");

4. Lastly, to access your IFRAME's src attribute:
    frame1.Attributes["src"] = "http://www.google.com";

Thanks Harish!!!

Comments

Armand du Plessis said:

I wrote a simple IFrame control a while back -> http://dotnet.org.za/armand/archive/2004/11/18/7151.aspx
# May 10, 2005 9:43 PM

Antonino (Argentina) said:

SomeBody could send me the code but for Visual Basic.net ???

I am trying but id doesn´t work.

Dim AreaCentral As HtmlControl

AreaCentral = Type(Me.FindControl("AreaCentral"),
HtmlControl)
AreaCentral.Attributes.Add("scr", "frwComprasWeb_Ofertas.aspx")

Says that i am making a reference to an object thats not an instance of an object

PLEASE !!!
# June 13, 2005 6:22 PM