You are on page 1of 33

Loading pages in IFRAME dynamically from codebehind - ASP.

NET

http://geekswithblogs.net/ranganh/archive/2005/04/25/37635.aspx

Project Cool
An ASP.NET Blog
posts - 319, comments - 4690, trackbacks 1010
Switch to Elastic Layout

<< Microsoft Innovation Days - Windows Vista, WPF/E, ASP.NET AJAX 1.0 | Home | Exploring ASP.NET AJAX Webcast >>

Loading pages in IFRAME dynamically from codebehind - ASP.NET

Click here for a Video version of this Article Most of us who develop Web Applications would have used an IFRAME during some stage of our lives. IFRAME's are an easy way by which you can embed another page within your original page such that you can show some important information like Stock position/Weather from another site without worrying about the changes happening to that site and updating the same. The Frame can also be used to show another page from your own application. ASP.NET also provides the option to have an IFRAME in our ASPX Pages. It can be with/without the "runat=server" attribute and does serve the purpose of embedding the page. The source for the frame can be set as follows:-

1 of 33

10/7/2010 6:19 PM

Loading pages in IFRAME dynamically from codebehind - ASP.NET

http://geekswithblogs.net/ranganh/archive/2005/04/25/37635.aspx

<IFRAME id="frame1" src="SourcePage.extension / URL of the external Site" scrolling="auto"> </IFRAME> However, in practical scenarios, we may want to load the page dynamically. In other words, we may want to specify the "src" attribute (the page which we want to show), dynamically. There is no straight forward way to do that and even if you add a "runat=server" attribute to it (though required in the work around provided below), you cannot access the "src" property directly. The workaround to do that is as follows:1. Specify the "runat=server" attribute as follows in the ASPX Page:<IFRAME id="frame1" scrolling="auto" runat="server"> </IFRAME> 2. In the codebehind, you may need to declare a HtmlGenericControl in the control declarations section as follows:C# protected System.Web.UI.HtmlControls.HtmlGenericControl frame1; (not required if working with ASP.NET 2.0, 3.5 i.e. Visual Studio

2005, 2008)

VB.NET Protected WithEvents frame1 As System.Web.UI.HtmlControls.HtmlGenericControl (not required if working with ASP.NET 2.0, 3.5 i.e.

Visual Studio 2005, 2008)

3. Then, you need to do a findcontrol to identify the control on the page and typecast it as follows:C# HtmlControl frame1 = (HtmlControl)this.FindControl("frame1"); (not required if working with ASP.NET 2.0, 3.5 i.e. Visual Studio 2005,

2008)

2 of 33

10/7/2010 6:19 PM

Loading pages in IFRAME dynamically from codebehind - ASP.NET

http://geekswithblogs.net/ranganh/archive/2005/04/25/37635.aspx

VB.NET Dim frame1 As HtmlControl = CType(Me.FindControl("frame1"), HtmlControl) (not required if working with ASP.NET 2.0, 3.5 i.e. Visual

Studio 2005, 2008)
Note: You can have different name for the Generic Control you define in the code behind, but for ease I keep both the same. The "frame1" referred in Find Control is the ID as declared in the ASPX Page. 4. Thereafter, you will be able to access the src property as follows:-

C# frame1.Attributes["src"] = "http://www.live.com" ;

VB.NET frame1.Attributes("src") = "http://www.live.com" ;

NOTE: Thanks PhOeNiX for providing the VB.NET equivalent. I have added the same now. As you can see though I have hard-coded the URL you can assign it dynamically based on a condition or any other business logic. This serves the purpose of dynamically loading the page in the IFRAME. A related article on Triggering an event in the Parent Page from within Page inside IFRAME

Cheers !!!

posted @ Monday, April 25, 2005 8:03 AM

3 of 33

10/7/2010 6:19 PM

NET Left by Lea McNabb at 5/3/2005 4:14 PM Thank you so much for such a helpful article!! I've been trying forever to figure out how to use a dynamic iFrame.NET fresher here.NET Left by Web'D at 5/4/2005 10:18 AM Hi.ASP. thanks!!!! # re: Loading pages in IFRAME dynamically from codebehind .NET Left by Thea Burger at 4/29/2005 6:25 AM Exactly what I was looking for.this appears to be just what I require. and this works perfectly! # re: Loading pages in IFRAME dynamically from codebehind .ASP.ASP..aspx Comments on this entry: # re: Loading pages in IFRAME dynamically from codebehind .ASP...net/ranganh/archive/2005/04/25/37635. . however require the same in 4 of 33 10/7/2010 6:19 PM ..NET http://geekswithblogs.Loading pages in IFRAME dynamically from codebehind .

NET http://geekswithblogs.ASP.net/ranganh/archive/2005/04/25/37635.ASP.ASP.Loading pages in IFRAME dynamically from codebehind . string reporttype) { HtmlControl frame1 = (HtmlControl)this.Attributes["height"] = "328px". string src = String.FindControl("frame1").NET Left by rafa at 5/13/2005 11:10 AM add myself to the "just what I was looking for!| group .aspx?ID=".Attributes["src"] = src. frame1. Thanx! # re: Loading pages in IFRAME dynamically from codebehind . frame1. # re: Loading pages in IFRAME dynamically from codebehind .-) # re: Loading pages in IFRAME dynamically from codebehind . Any ideas would be FAB.Concat("RateResultsReport. key. } 5 of 33 10/7/2010 6:19 PM .aspx VB. Quick and perfect.Attributes["width"] = "100%".NET and am using inline coding rather than codebehind.ASP. "&reporttype=". /// <summary> /// Create the IFrame attributes for the Output /// </summary> /// <param name="key">The key</param> /// <param name="reporttype">The type of Report being requested</param> private void CreateSubReport(string key.NET Left by Tadd Stuart at 5/17/2005 3:27 PM Here is a routine that could help others based on your solution. reporttype). frame1.NET Left by Luis Ferreira at 5/9/2005 1:51 PM Just what we needed.

however.NET Left by Ian at 6/11/2005 4:22 AM Thanks! It worked good for me to.ASP.ASP. when it navigates from one page to another.net/ranganh/archive/2005/04/25/37635.ASP.NET domain.NET http://geekswithblogs. Any suggestions? # re: Loading pages in IFRAME dynamically from codebehind . # re: Loading pages in IFRAME dynamically from codebehind . # re: Loading pages in IFRAME dynamically from codebehind .aspx # re: Loading pages in IFRAME dynamically from codebehind . # re: Loading pages in IFRAME dynamically from codebehind . This external application uses session variables extensively..NET Left by MADHUSUDAN at 5/29/2005 5:57 AM B.very useful and simple! just what i needed! # re: Loading pages in IFRAME dynamically from codebehind .ASP. it loses the session variables.Net 2003).Loading pages in IFRAME dynamically from codebehind .NET Left by Teo at 6/3/2005 3:32 PM Thanks! Really useful.Net web form.congratiulations. You rule! If I name the HTMLGenericControl with the same name as the IFrame I don't need to do the typecast and it works (VS .Tech fresher seeking a job in .NET Left by b4silence at 5/21/2005 4:04 PM man.NET Left by David Kendrick at 6/21/2005 7:07 PM 6 of 33 10/7/2010 6:19 PM .ASP...ASP.NET Left by David Kendrick at 6/21/2005 7:07 PM I have a scenario in which I am loading a separate classic-ASP application into an IFRAME which I have programmatically embedded into an ASP.ASP.

.ASP.Loading pages in IFRAME dynamically from codebehind . What could be causing the error?? # re: Loading pages in IFRAME dynamically from codebehind .net/ranganh/archive/2005/04/25/37635.NET Left by suparna at 7/20/2005 10:54 AM it doesnt give the Parent control.NET Left by Vitor Mata at 7/2/2005 1:58 AM Man..NET Left by RAJAN at 7/7/2005 9:15 AM WOW Great Dude. My most sincere thanks! Cheers mate! # re: Loading pages in IFRAME dynamically from codebehind . # re: Loading pages in IFRAME dynamically from codebehind .NET Left by Vicky at 7/7/2005 6:34 AM I tried you example..ASP... when it navigates from one page to another. but for some reason.ASP.. exactly what i was looking for.ASP.ASP. "obj reference not set to an instance of an obj". you should have a statue just for this article! I mean it! :D I was searching for something like this for ages. however. thank you very very much . Any suggestions? # re: Loading pages in IFRAME dynamically from codebehind .FindControl("frame1") it throws an exception Object reference not set to an instance 7 of 33 10/7/2010 6:19 PM .Net web form.aspx I have a scenario in which I am loading a separate classic-ASP application into an IFRAME which I have programmatically embedded into an ASP. This external application uses session variables extensively. it throws an exception.Parent. If i write this.NET http://geekswithblogs. it loses the session variables.

.ASP.NET Left by Markt at 8/16/2005 12:44 PM Vicky : you didn´t set the tag to "runnat=server" # re: Loading pages in IFRAME dynamically from codebehind .ASP.ASP.Loading pages in IFRAME dynamically from codebehind ..ASP.this was a one stop look for exactly what i needed.ASP..NET Left by Rishi at 8/2/2005 4:44 PM Jus' what the patient needed.NET Left by Mark at 8/27/2005 3:16 AM And to say it once again!!!!! Thanks very much.aspx # re: Loading pages in IFRAME dynamically from codebehind .net/ranganh/archive/2005/04/25/37635.Thanks for ur help.NET Left by Danielle at 9/15/2005 2:34 PM 8 of 33 10/7/2010 6:19 PM .ASP.ASP.NET http://geekswithblogs.NET Left by MarianoK at 8/20/2005 8:05 PM Thanks a lot for sharing this !!!! It beat the previous method I was using (Client-side script) I hope you don't mind if I put a link to your site in the "THANK YOU" section of mine !!! # re: Loading pages in IFRAME dynamically from codebehind . This code got me what I wanted in 10 minutes # re: Loading pages in IFRAME dynamically from codebehind .com # re: Loading pages in IFRAME dynamically from codebehind .NET Left by David Larew at 9/9/2005 1:44 AM Thanks!!! How could I write a soap method response to it? davidlarew@hotmail. # re: Loading pages in IFRAME dynamically from codebehind . I spent hours trying to deal with z-index to no avail.

It sure saved a lot of strugles for many. Given exactly what i was looking for in the right context.NET Left by sash at 9/22/2005 3:57 AM This is a template for explaining any tech stuff. Thanks for sharing great stuff. Nothing more.NET http://geekswithblogs.ASP.aspx how to find control in VB syntax? HtmlControl frame1 = (HtmlControl)this.NET 9 of 33 10/7/2010 6:19 PM . Just perfect. nothing less.net/ranganh/archive/2005/04/25/37635.Loading pages in IFRAME dynamically from codebehind . # re: Loading pages in IFRAME dynamically from codebehind . Cheers mate # re: Loading pages in IFRAME dynamically from codebehind . # re: Loading pages in IFRAME dynamically from codebehind .ASP. Thanks for sharing great stuff.NET Left by Krishan Ariyawansa at 9/19/2005 11:14 PM Man your cool. Keep up the good work !!!!!! # how to use the user controls of base page where iFrame define re: Loading pages in IFRAME dynamically from codebehind .FindControl("frame1") Did anybody wrote in vb? Cheers to Harish .ASP.NET Left by shaan_26 at 9/22/2005 9:05 AM i want immidiate solution plz help me !! # re: Loading pages in IFRAME dynamically from codebehind . It sure saved a lot of strugles for many.FindControl("frame1") Did anybody wrote in vb? Cheers to Harish .ASP.ASP.NET Left by help me at 9/16/2005 7:09 AM how to find control in VB syntax? HtmlControl frame1 = (HtmlControl)this.ASP.

.Web.NET Protected WithEvents frame1 As System.NET Left by Jim at 10/17/2005 9:14 AM Great! I've been looking for this for weeks! 10 of 33 10/7/2010 6:19 PM ... HtmlControl) Dim src As String = String..Attributes("src") = src .ASP..ASP.NET Left by shafi ahmed at 10/5/2005 5:05 AM thank for help # re: Loading pages in IFRAME dynamically from codebehind . key.This was very useful.aspx Left by PhOeNiX at 9/30/2005 1:32 PM The same code in VB.NET Left by happy at 10/10/2005 7:28 PM Thanx.Concat("RateResultsReport.ASP.Attributes("height") = "328px" End With # re: Loading pages in IFRAME dynamically from codebehind .Loading pages in IFRAME dynamically from codebehind ...ASP.UI. # re: Loading pages in IFRAME dynamically from codebehind .Attributes("width") = "100%" ..NET http://geekswithblogs.thank u and google..I need it. "&reporttype=". reporttype) With frame1 ..HtmlControls. # re: Loading pages in IFRAME dynamically from codebehind .FindControl("frame1").ASP.net/ranganh/archive/2005/04/25/37635.NET Left by Arasu at 10/3/2005 8:17 AM nice.HtmlGenericControl Dim frame1 As HtmlControl = CType(Me.aspx?ID=".and find it.

You can change this dynamically in the code behind as you can see # re: Loading pages in IFRAME dynamically from codebehind . frame1. # re: Loading pages in IFRAME dynamically from codebehind .Attributes["height"] = "328px". but how can hide IFRAME? # re: Loading pages in IFRAME dynamically from codebehind .ASP.NET Left by Albert at 11/11/2005 5:44 AM can i adjust the height dinamically too?? # re: Loading pages in IFRAME dynamically from codebehind .ASP.ASP.aspx # re: Loading pages in IFRAME dynamically from codebehind .NET Left by John Pearson at 11/18/2005 7:05 PM 11 of 33 10/7/2010 6:19 PM .ASP.com? Thanks heaps. Can some please copy it and send it to me at jonesy_boy10@hotmail.NET Left by Paul Jones at 11/17/2005 9:10 PM I can't see the code on this page properly for some reason.ASP.net/ranganh/archive/2005/04/25/37635.Attributes["width"] = "100%".NET Left by Paul Jones at 11/9/2005 9:33 PM Can't see the code :( # re: Loading pages in IFRAME dynamically from codebehind .NET Left by Gustavo at 11/16/2005 3:04 PM Excelente!!!.NET http://geekswithblogs. You can do frame1.NET Left by Harish at 11/11/2005 5:47 AM Check one of the feedbacks above.Attributes["src"] = src.ASP.ASP. frame1.Loading pages in IFRAME dynamically from codebehind .

ASP.NET Left by Rachita at 12/21/2005 1:29 AM 12 of 33 10/7/2010 6:19 PM . pls help # re: Loading pages in IFRAME dynamically from codebehind .NET Left by Aftab at 12/1/2005 8:33 AM I would like to know if i can set the innerText or innerHTML property dynamically just like frame1.NET Left by Mike McMorrow at 11/21/2005 6:34 PM Magnifico! Just what the doctor ordered! A simple. You solved my problem on first search took me 10 mins to fix find the solutions and implement it.net/ranganh/archive/2005/04/25/37635. simple and to the point.Loading pages in IFRAME dynamically from codebehind .ASP.com # re: Loading pages in IFRAME dynamically from codebehind .ASP.supanet. It didnt work for me.NET Left by JordansGhost at 12/8/2005 7:52 AM Ideal.ASP.NET Left by Anand Patil at 12/2/2005 2:12 PM Its really good article which i am looking for. # re: Loading pages in IFRAME dynamically from codebehind . but I can't see the code either! I would appreciate a copy at john@sides-pearson.aspx Sounds just what I'm looking for.ASP.Attributes["innerHTML"] = "<p>hello</p>". *pats author on back* # re: Loading pages in IFRAME dynamically from codebehind . excellent # re: Loading pages in IFRAME dynamically from codebehind .NET http://geekswithblogs.ASP. sturdy solution.

# re: Loading pages in IFRAME dynamically from codebehind .ASP.aspx I am using a SPAW text editor.Loading pages in IFRAME dynamically from codebehind .Net would recognize or accept adding.ASP. i want that the text edited with text editor placed on a page must appear in an iframe placed on the next page.NET Left by virdun at 1/12/2006 8:42 AM I could'nt get it to work so I did this: <asp:Label id="lblIframe" runat="server"></asp:Label> lblIframe. # re: Loading pages in IFRAME dynamically from codebehind .net/ranganh/archive/2005/04/25/37635. How can this be done? # re: Loading pages in IFRAME dynamically from codebehind .Text = "<iframe src=url></iframe>".NET Left by Chris Davey at 1/31/2006 5:52 AM 13 of 33 10/7/2010 6:19 PM . Very useful! # re: Loading pages in IFRAME dynamically from codebehind . Thanks for the code.ASP. Why wouldn't the src be an attribute that ASP. How can this be done? # re: Loading pages in IFRAME dynamically from codebehind .NET http://geekswithblogs.NET Left by Coder at 1/23/2006 8:59 PM Thanks very much! Exactly what I'm looking for.ASP. Hard to believe something that should be so easy to do is difficult in ASP.ASP.ASP.NET Left by Ricky at 12/21/2005 1:36 AM I am using a SPAW text editor.Net. i want that the text edited with text editor placed on a page must appear in an iframe placed on the next page.NET Left by Bruce at 1/19/2006 12:46 PM Excellent.

Loading pages in IFRAME dynamically from codebehind .ASP.Attributes["width"] = "100%". I want to build a page in memory as a text stream and dump it into the iframe.FindControl("FormArea"). Being new to ASP/C# does anyone know why I get an Object reference not set to an instance of an object exception when using the example code above? Aspx file has: <iframe runat="server" id="image1" name="image1" src="" height="" width=""> </iframe> C# file has: HtmlControl frame1 = (HtmlControl)this.NET Left by casey at 2/20/2006 2:46 PM <Quote> I could'nt get it to work so I did this: <asp:Label id="lblIframe" runat="server"></asp:Label> 14 of 33 10/7/2010 6:19 PM . frame1.Attributes["height"] = "100%".NET http://geekswithblogs.gif".NET Left by Andrew Mercer at 2/16/2006 7:53 AM Hi.ASP. frame1. Andrew # re: Loading pages in IFRAME dynamically from codebehind .aspx Anyone know if/how it is possible to inject the HTML into the response stream of the iframe. # re: Loading pages in IFRAME dynamically from codebehind .ASP. Thanks in advance. frame1.Attributes["src"] = "~/images/Test.net/ranganh/archive/2005/04/25/37635.

u have done a great job. # re: Loading pages in IFRAME dynamically from codebehind . it will not work. Any ideas why? Frame1 = CType(Me.. </quote> That method also works but if you need to place two iframes on the same page and need them in a certain spot. Keep on posting new things which will be helpful for us like this one..Loading pages in IFRAME dynamically from codebehind .net..ASP.. The label method will stack them on top of each other.NET http://geekswithblogs.ASP.ASP. Email if someone has a solution.NET Left by Wendi at 5/2/2006 7:25 PM This is a great solution.NET 15 of 33 10/7/2010 6:19 PM .aspx lblIframe.ASP.wendit@selltis. this is what I was looking for.net/ranganh/archive/2005/04/25/37635.com # re: Loading pages in IFRAME dynamically from codebehind .NET Left by Kenny at 4/14/2006 8:15 PM Awesome code! Thanks for posting something usable! # re: Loading pages in IFRAME dynamically from codebehind .NET Left by Raj Shimpi at 4/3/2006 5:15 AM Hey man.Text = "<iframe src=url></iframe>"..NET Left by iqbal at 5/4/2006 8:43 AM It is possible programmatically access a label control which lives in my iframe? # re: Loading pages in IFRAME dynamically from codebehind .FindControl("Frame1").ASP.ASP.. # re: Loading pages in IFRAME dynamically from codebehind . but does not work with a Masterpage setup in asp. HtmlControl) returns nothing.

ASP.NET Left by Fred at 6/1/2006 11:16 AM I cannot see anything in the two frames. # re: Loading pages in IFRAME dynamically from codebehind .ASP.NET http://geekswithblogs.ASP.NET Left by srini at 5/29/2006 10:32 AM I am not able to eecuting.net/ranganh/archive/2005/04/25/37635. # re: Loading pages in IFRAME dynamically from codebehind . # re: Loading pages in IFRAME dynamically from codebehind .ASP. but then it stopped working. It worked fine until I changed to using master pages.aspx Left by ProphetCat at 5/8/2006 6:33 PM I'm having the same problem. Just what we needed.ASP. 16 of 33 10/7/2010 6:19 PM .Loading pages in IFRAME dynamically from codebehind .NET Left by Ray at 6/6/2006 11:49 AM First.NET Left by Huy at 5/19/2006 6:38 PM If you use MasterPage. It can't find the control on the page.NET Left by arvindc at 5/23/2006 7:04 PM great!!! Keep helping people this way. many thanks for the code.when i execute this the browser page is not showing any thing(its in same page and task bar is blinking can you please tell me thanks # re: Loading pages in IFRAME dynamically from codebehind .ASP. the FindControl() has to be overridden to be recursive. # re: Loading pages in IFRAME dynamically from codebehind .

Attributes("width") = "100%" doesn't! Does anyone have any solution for either of these problems? # re: Loading pages in IFRAME dynamically from codebehind .aspx I have a panel which contains the Iframe in the content area of the master page: <asp:Content ID="Content1" ContentPlaceHolderID="PageContentPlaceHolder" Runat="Server"> <asp:Panel ID="Panel1" runat="server" Width="100%" Height="100%"> <iframe runat=server id="_content" name="_content" marginheight =0 marginwidth =0></iframe> </asp:Panel> </asp:Content> I can access the Iframe by using: Dim frame1 As HtmlControl = CType(Me.ascx wich has an iframe on it pointing to another .ascx..Attributes("src") = ResolveUrl(Request. HtmlControl).net/ranganh/archive/2005/04/25/37635. 2) I want to set the size of the Iframe to the size of the page it contains (within limits).Panel1.Loading pages in IFRAME dynamically from codebehind . It is as follows: I got these . by using a url= querystring: frame1.Attributes("width") = "1000px" works but frame1. in the master page. but '100%' doesn't work at all. i. This way I can send content there from a menu in the master page. I can set it to hard-coded values. I have 2 problems: 1) Mouseover on my TreeView menu.ASP. I'mm having some issues with iframes.ASP. frame1.NET Left by ABlanco at 6/16/2006 3:22 PM Hi. causes the Iframe to redraw every time = very bad flickering.e.NET http://geekswithblogs.FindControl("_content").QueryString("url")) However. I need some information that is produced in the ascx contained by the iframe to show it in the main control how can i 17 of 33 10/7/2010 6:19 PM ..

NET Left by Sher. 18 of 33 10/7/2010 6:19 PM . I need to load the item list from an iframe.Loading pages in IFRAME dynamically from codebehind .NET http://geekswithblogs.ASP.ASP. I have a page that is like a catalog. This means that I have to find a way to get the parameter in the parent page and do postback.Net at 6/22/2006 2:01 PM Hey dude! Fantastic!. to the parent page. to show the different ID cards. Any ideas? # re: Loading pages in IFRAME dynamically from codebehind . Many thanks.NET Left by Krishna at 7/7/2006 11:21 AM Hey Guys. but my problem is that I need to send a parameter from the iframe.ASP.net/ranganh/archive/2005/04/25/37635. I haven't tried it but it appears in my property list.NET Left by Offir at 6/17/2006 1:29 PM Hi everyone. I would write it like this: frame1.Attributes("style")="width:100%" Hope it works # re: Loading pages in IFRAME dynamically from codebehind . so I can show the ID Card of the item that was clicked in the iframe.ASP. # re: Loading pages in IFRAME dynamically from codebehind .NET Left by Offir at 6/17/2006 1:20 PM Ray.ASP.aspx get this information from the ascx running in the iframe???? # re: Loading pages in IFRAME dynamically from codebehind . and this works fine. can you tell me how to print the iframe from code behind after assigning the "src" attribute. maybe for your second problem you should use style for setting your page width.

NET 19 of 33 10/7/2010 6:19 PM .Controls.NET Left by grateful at 7/10/2006 5:44 PM works great! here's a version i have modified that adds the entire iframe to the page dynamically. you can run this script over and over again to add many iframes: On the .ASP.HtmlGenericControl("iframe"). you'll need a placeholder(s) where the iframe(s) will be rendered: <asp:PlaceHolder ID="theFrameHolder" runat="server" /> Then in the code behind. The one by "grateful" has really been helpful and i am really Grateful to him/her. in case anyone is interested.Attributes["scrolling"] = "auto". # re: Loading pages in IFRAME dynamically from codebehind .aspx page.msn.Loading pages in IFRAME dynamically from codebehind .net/ranganh/archive/2005/04/25/37635.HtmlControls.com".aspx # re: Loading pages in IFRAME dynamically from codebehind .Web.NET http://geekswithblogs.ASP. Thanks. theFrameHolder. create and add the iframe to the placeholder: HtmlControl frame1 = new System.NET Left by Abhishek at 7/13/2006 3:23 PM Thanks for the comments.NET Left by Andy at 7/13/2006 2:36 PM Thanks to everyone who has contributed to this page. # re: Loading pages in IFRAME dynamically from codebehind .Attributes["frameborder"] = "1". frame1.ASP. cheers!!! # re: Loading pages in IFRAME dynamically from codebehind .Add(frame1). frame1.UI.ASP. especially last comment which really got this sorted for me.Attributes["src"] = "http://search.ASP. frame1.

document. Unfortunately.net/ranganh/archive/2005/04/25/37635.all ) { h = document.style.all ) { h = document.height = h + 30 + 'px'.scrollHeight.aspx Left by PAM at 7/28/2006 7:53 AM Thank's.blockrandom.getElementById('iframe').NET Left by nickos at 8/4/2006 6:10 AM this is a way to dynamically set the height depending on the page content: <script language="javascript" type="text/javascript"> function iFrameHeight() { var h = 0. You save my vacantions ..ASP.contentDocument.all.height = h + 70 + 'px'. } } </script> <iframe id="iframe" name="iframe" src="" width="100%" height="500" scrolling="auto" frameborder="0" class="wrapper" allowTransparency="true" runat="server" > This option will not work correctly. # re: Loading pages in IFRAME dynamically from codebehind . your browser does not support Inline Frames </iframe> 20 of 33 10/7/2010 6:19 PM . } else if( document.NET http://geekswithblogs.body. if ( !document.style.height. document.ASP.getElementById('iframe').frames('iframe').Loading pages in IFRAME dynamically from codebehind . document..

height = h + 70 + 'px'. # re: Loading pages in IFRAME dynamically from codebehind .all.all ) { h = document.aspx however because of the mix of javascript & runat=server.height. document.height = h + 30 + 'px'. } } </script> # re: Loading pages in IFRAME dynamically from codebehind .ASP.document.net/ranganh/archive/2005/04/25/37635.ASP.getElementById('iframe').ASP.getElementById('iframe'). } else if( document.NET Left by Kishore Kumar AVN at 8/4/2006 8:56 AM Thanks You save my Time # re: Loading pages in IFRAME dynamically from codebehind .frames('iframe').Attributes.scrollHeight.ASP.NET Left by nickos at 8/7/2006 1:55 PM sorry. "iFrameHeight().style. javascript in dynamic page should have been as follows <script language="javascript" type="text/javascript"> function iFrameHeight() { var h = 0. in the Page_Load or similar.style.contentDocument.all ) { h = document.Loading pages in IFRAME dynamically from codebehind .Add("onload". if ( !document.NET Left by Ed McPeak at 8/7/2006 7:42 PM 21 of 33 10/7/2010 6:19 PM . you'll also need this (c#) iframe.iframe.").body. document.NET http://geekswithblogs.

NET Left by seand at 8/28/2006 5:10 PM This works great .Reply me its urgent...NET Left by Preethi at 9/13/2006 9:05 AM thanx a lot..net/ranganh/archive/2005/04/25/37635.. # re: Loading pages in IFRAME dynamically from codebehind ..ASP. # re: Loading pages in IFRAME dynamically from codebehind .NET Left by Graham at 8/25/2006 10:05 AM Thanks nickos it works really well.Loading pages in IFRAME dynamically from codebehind .ASP..net 2005 enviroment my email is praveen..singh21@gmail.ASP.NET Left by chandru at 9/13/2006 4:51 AM when i open the doc.ASP.ASP.How can we?...For me it should not show as such like when we open pdf file..NET http://geekswithblogs.NET Left by Praveen at 9/15/2006 4:36 AM i am not able to set height dynamically even after using javascript i am working in .. Thanks in advance.ASP..aspx Too cool! This information on this page was extremely valuable! Excellent code example! # re: Loading pages in IFRAME dynamically from codebehind .com if u can help me it will be great 22 of 33 10/7/2010 6:19 PM . # re: Loading pages in IFRAME dynamically from codebehind .xls.has anyone had any browser issues(safari on the mac specifically) with Iframes # re: Loading pages in IFRAME dynamically from codebehind .and ppt file using iframe it shows open save dialog box....

# re: Loading pages in IFRAME dynamically from codebehind .Loading pages in IFRAME dynamically from codebehind . I did with MyFrame.Attributes("srd") = "http://whatever. Me. take out the Dim line altogether.ASP.. so you have to rename it.. When you do the Protected WithEvents frame1.frame1. Therefore.ASP.ASP.net/ranganh/archive/2005/04/25/37635. This is what did it for me.NET Left by Jarred at 9/29/2006 5:57 AM How do I redirect the parent page from within the IFrame using codebehind (C#) # re: Loading pages in IFRAME dynamically from codebehind . Then in a click event for something like a Link Button just put the line. and then try to dim frame1 your get a problem . Here is what I did to get around that. This though led to the object error.ASP..NET Left by Buz Meg Yall at 10/7/2006 10:20 PM Andrew Mercer I had the same problem as you with the Object reference not set to an instance of an object error.frame1 is already declared as 'Protected Dim with events.aspx # re: Loading pages in IFRAME dynamically from codebehind .NET http://geekswithblogs. or anything for that matter)? # re: Loading pages in IFRAME dynamically from codebehind .NET Left by Phoenixian at 10/27/2006 1:56 PM 23 of 33 10/7/2010 6:19 PM ..com" Note that the url must be enclosed in double quotes or you will get an http is not declared problem.ASP.NET Left by JeffOakman at 10/3/2006 12:08 PM Did anyone ever find a way to communicate from within the iframe to the parent page (make it do a redirect..

....net/ranganh/archive/2005/04/25/37635.NET Left by ajay at 11/10/2006 5:21 AM any way bt which we can display two IFRAMES with a single IFRAME tag.ASP..ASP..NET http://geekswithblogs.it helps me a lot. this was great help.NET Left by Rachna at 11/1/2006 10:58 AM Thanks ..Loading pages in IFRAME dynamically from codebehind . # re: Loading pages in IFRAME dynamically from codebehind ... when i click a link an IFRAME should be opened and when i click the second link another IFRAME should be opened. you cannot code this example.aspx Thanks folks.ASP. # re: Loading pages in IFRAME dynamically from codebehind .. Without knowing what this is... any ideas??? # re: Loading pages in IFRAME dynamically from codebehind . i have to enter text in a textbox. both the IFRAMES should contain the text i enter in the textbox...NET Left by vikas at 11/1/2006 11:44 AM i cant see the code can anyone send me the code at register2spider@yahoo.. the problem is like this.NET Left by venu gopal at 12/19/2006 4:01 AM its amaging. # re: Loading pages in IFRAME dynamically from codebehind . It was really a good example..ASP.ASP..NET Left by J Leonard at 11/24/2006 9:24 PM Does not work as data example code in the boxes is missing after first and second "as follows". 24 of 33 10/7/2010 6:19 PM .com # re: Loading pages in IFRAME dynamically from codebehind ...ASP.

aspx thanks for the aricle and thanks for the coperation Venu # re: Loading pages in IFRAME dynamically from codebehind .Loading pages in IFRAME dynamically from codebehind . Not sure about FireFox.NET Left by John Baughman at 1/3/2007 11:43 PM The source frames are pointing to "about:blank" in IE.net/ranganh/archive/2005/04/25/37635.ASP.NET Left by uyduruk at 2/6/2007 8:17 PM hi friends.ASP."url"). 25 of 33 10/7/2010 6:19 PM .ASP.addAttribut("src". that´s all sorry guys.NET http://geekswithblogs.ASP. # re: Loading pages in IFRAME dynamically from codebehind .name. # re: Loading pages in IFRAME dynamically from codebehind ..NET Left by 9 at 1/16/2007 4:58 PM ohhhhhhhhhhhhhhhhhhhhh sorry i´m sorry i´m so scarred with this solution !!!! i din´t read the posts but if you put runat=server in a htmlcontrol in the html interface automaticaly you have this control in server side you don´t need a find control and bla bla bla all you have is something like that html side <iframe width="100%" height="100%" runat="server" id="name"/> server side this.

NET Left by DarkChuky at 2/26/2007 2:46 PM This code is great and easy to use.HtmlGenericControl("iframe").msn.. Does print only print one frame per page? How can i make the frame to continue to the next page? Any ideas? Thanks in advance!!!! # re: Loading pages in IFRAME dynamically from codebehind .. the content on the frame does not continue into the next page.Loading pages in IFRAME dynamically from codebehind .Web.NET http://geekswithblogs. 26 of 33 10/7/2010 6:19 PM .. It works when i click "view in browser" but not when i press F5. I have 2 pages embedded in 2 iframes in my aspx page.HtmlControls. frame1.net/ranganh/archive/2005/04/25/37635. frame1. # re: Loading pages in IFRAME dynamically from codebehind . it works!!!! "On the . I could not fix it.UI.ASP.Attributes["frameborder"] = "1". Regards..ASP. create and add the iframe to the placeholder: HtmlControl frame1 = new System. thanks.. frame1.ASP. you'll need a placeholder(s) where the iframe(s) will be rendered: <asp:PlaceHolder ID="theFrameHolder" runat="server" /> Then in the code behind.aspx I am designing a web app using vb.net 2003 and i placed an iframe on aspx page..com".Attributes["src"] = "http://search.aspx page. Thanks in advance for your time. When I do a print preview.NET Left by help at 2/15/2007 12:35 PM Hi.Attributes["scrolling"] = "auto".

ASP.NET Left by Nivrutti at 3/14/2007 6:46 AM Hi Thanks for posting such nice article on IFrame and also thanks to all persons who posted there comments on this page which really helps lot But i have one problem when we use placeholder as given in above example use the same code then how to adjust width and hight of the placeholder pls help me # re: Loading pages in IFRAME dynamically from codebehind .ASP.ASP..NET Left by M N Anish at 3/14/2007 10:22 AM Realy informative.Add(frame1).ASP.NET Left by Nivrutti at 3/14/2007 7:44 AM i have tried the above code but my SlideMenu hides behind IFRAME at run time can any one help me? # re: Loading pages in IFRAME dynamically from codebehind . my problem is i have a one ifram which have hyperlinks. i want that data in other ifram . so plz help me in this.. " # re: Loading pages in IFRAME dynamically from codebehind .NET http://geekswithblogs.. 27 of 33 10/7/2010 6:19 PM . when ever i click on that it display contain of it in same ifram.aspx theFrameHolder.Loading pages in IFRAME dynamically from codebehind .net/ranganh/archive/2005/04/25/37635.Controls.ASP.NET Left by denish at 2/28/2007 10:26 AM hi.. # re: Loading pages in IFRAME dynamically from codebehind .

ASP. this is returning null?????? plz help me umer.Loading pages in IFRAME dynamically from codebehind . Is it possible in Iframe it loads another page without refresh # re: Loading pages in IFRAME dynamically from codebehind . On click of menu it loads the different page.ASP. I want to use IFrame within a Update Panel of Atlas.ASP.NET Left by Siddique at 4/10/2007 6:29 AM Thanks to all of you on Excellent Job. But when different page loads it refresh the page.aspx Thanks a lot # re: Loading pages in IFRAME dynamically from codebehind . I am using asp.NET Left by Sam at 3/19/2007 8:17 AM I am able to directly access the "src" property of the IFrame directly.ASP.NET Left by faouzi yassine at 4/17/2007 5:05 AM Or you can do this : <iframe id = "TreeTD" height="690px" src="<%=siteUrl%>" width="100%" frameborder = '0'></iframe> siteUrl is a variable of your code behind # re: Loading pages in IFRAME dynamically from codebehind .NET Left by umer at 5/2/2007 9:02 AM hey HtmlControl frame1 = (HtmlControl)this.com 28 of 33 10/7/2010 6:19 PM .FindControl("frame1"). without the requirement of the workaround provided here! But it's definitely a good information # re: Loading pages in IFRAME dynamically from codebehind .khan@systemsltd.net/ranganh/archive/2005/04/25/37635.ASP.NET http://geekswithblogs.net Menu.

NET Left by umer at 5/2/2007 11:22 AM hey i got frame but. i m stuck how to get control i mean what i did TextBox tx = new TextBox(). # re: Loading pages in IFRAME dynamically from codebehind .ASP.FindControl("frame1").aspx # re: Loading pages in IFRAME dynamically from codebehind .NET Left by NoName at 9/20/2007 3:09 PM HtmlControl frame1 = (HtmlControl)this. We had a placeholder and then wrote the html to it. HtmlControl frame1 = (HtmlControl)this. I tried using 29 of 33 10/7/2010 6:19 PM .ASP. .NET http://geekswithblogs.ASP.... if (frame1 != null) tx = (TextBox)frame1...ASP..FindControl ("txtFirst"). You cannot declare the same id for the same control on the same page. u cant find control from iframe . literally. the code behind page and the source code page are the same.FindControl("frame1") returns null.NET Left by Matt at 5/25/2007 10:06 AM Have just started a rewrite of some v v nasty code and thought I'd start by seeing if there was a better way to do this then we used. I'm not a fan but this is a much better way. good work. And declaring it in code behind as "frame1" same as the iframe id which is "frame1" gives an error..net/ranganh/archive/2005/04/25/37635... some one said.ASP.Loading pages in IFRAME dynamically from codebehind .NET Left by demon at 8/10/2007 7:13 AM Hi thx U save me a lot of searching # re: Loading pages in IFRAME dynamically from codebehind . plz help me # re: Loading pages in IFRAME dynamically from codebehind ..

ASP. when i am in truble. # re: Loading pages in IFRAME dynamically from codebehind .ASP. the src attribute for the iframe should be blank..Attributes["src"] = //url. # re: Loading pages in IFRAME dynamically from codebehind .net/ranganh/archive/2005/04/25/37635..Loading pages in IFRAME dynamically from codebehind . this worked for me. or otherwise obfuscated. I'm sure this can be applied to a bunch of stuff. In other words.aspx this. 30 of 33 10/7/2010 6:19 PM . # re: Loading pages in IFRAME dynamically from codebehind . thanks man. thanks for the primer! Way to go. because the page already has the frame1 control on it.NET Left by Seth at 9/26/2007 7:07 AM Thanks.ASP.NET Left by miss jyoti sopan pokharkar at 12/12/2007 7:18 PM Thank you.ASP. it was really helpful for me:) i generally use your site. Is there any way to accomplish this? Thanks in advance.NET Left by Ozzie at 12/6/2007 12:25 AM Shweeet. No other declaration. the code works great! My problem is that I do not want the URL of the site in the iFrame to show up in the client-side source code..frame1.NET http://geekswithblogs.

NET http://geekswithblogs..net/ranganh/archive/2005/04/25/37635. asp. # re: Loading pages in IFRAME dynamically from codebehind .NET Left by pankaj at 1/17/2008 9:16 PM how to show dynamically created xml file in iframe .netfdslkfsdjflsadf # "How to update an iFrame upon a change event from a different iFrame?" . # re: Loading pages in IFRAME dynamically from codebehind .. IOL Broadband pvt ltd. # rHow to Load Two IFRAME dynamically from codebehind . Please help # re: Loading pages in IFRAME dynamically from codebehind .NET Left by suman at 1/21/2008 8:59 PM how to write ifram in asp.aspx Thanks and Regards. Thank you very much. Jyoti S Pokharkar.net developer.ASP.NET Left by Neerman at 12/31/2007 4:02 AM I would like to know if we have two iframe in a same asp.net # re: Loading pages in IFRAME dynamically from codebehind .ASP.ASP.how could we show the content of the two prame on page load.ASP.The xml file is a string(in memory) and not saved as an xml file.ASP.NET Left by Jon Hawkins at 12/13/2007 12:51 AM Just what I was looking for.Loading pages in IFRAME dynamically from codebehind .ASP.ASP.NET Left by Bill New at 2/5/2008 6:15 AM 31 of 33 10/7/2010 6:19 PM .net web page.NET Left by suman at 1/21/2008 8:57 PM how to write ifram in asp.

Passes iFrame Name to Parser ASPX file. and Opera 9. The Parser ASPX file is what is not currently able to handle the reference to the existing iFrame which was created by the Driver ASPX file.Loading pages in IFRAME dynamically from codebehind . Display ASPX file which shows the information.x. Major issue however is that it causes all Internet Browsers to blink it seems when an update occurs. Internet Explorer 7.ASP. Driver ASPX file that builds the layout of the page with different iFrame ID's. (Internet Explorer 6. Parser ASPX file that checks to see if there have been any changes that need to be handled. Netscape 9. 3. don't update the iFrame.asp. .NET http://geekswithblogs. Firefox 2. I have 2 asp pages that will do this now BUT ONLY in Internet Explorer 6 or Internet Explorer 7 there is a VERY annoying blink every time the page updates.x. for example) that needs to update the other iFrame.aspx 32 of 33 10/7/2010 6:19 PM . Instead of checking for the update on the web page and updating the web page every say 30 seconds. Netscape. Don't have this issue in these Internet Browsers Firefox.net/t/1213208. I have all the logic that is needed EXCEPT for the call to update the other frame! I have these 3 ASPX pages: 1. . 2. Perhaps this will better explain what I need to do: http://forums. only update when a change to the page occurs.x.Uses standard META tag Refresh to do the looping and cookies to manage the variables. It works on the SAME ASPX page. or Opera.x.net/ranganh/archive/2005/04/25/37635.x!) I need to update another iFrame ONLY when the ASPX page that automatically determines there is a change (a newer picture.aspx Interesting Article. So if the highest picture to be shown on a page is the same as the last time.

aspx This is at least a step in the right direction.NET http://geekswithblogs.NET Left by Komila at 2/21/2008 5:16 PM Gravatar 33 of 33 10/7/2010 6:19 PM . Thanks! # re: Loading pages in IFRAME dynamically from codebehind .NET Left by Smita at 2/13/2008 12:52 PM This was a great help.ASP.NET Left by LS at 2/6/2008 10:15 PM Hi.ASP.ASP.ASP.NET Left by bj at 2/18/2008 9:52 AM Can I scroll the iframe to a certain position on the page? Thanks! # re: Loading pages in IFRAME dynamically from codebehind . # re: Loading pages in IFRAME dynamically from codebehind . Can anyone tell mw how to display a dynamically created pdf generating binary output to the iframe src without creating any pdf file physically on the disk.Loading pages in IFRAME dynamically from codebehind .ASP. thanks # re: Loading pages in IFRAME dynamically from codebehind .net/ranganh/archive/2005/04/25/37635.