Error!
Success!

iframe source on the fly

0
kicks

iframe source on the fly  (Unpublished)

This article will explain that how to load pages dynamically in IFrame from the code behind. Actually few days back I encountered a situation where I was interested to set the src of IFrame dynamically. Some of the solutoin which I found on the internet were some thing like this: Declare a Generic control: protected System.Web.UI.HtmlControls.HtmlGenericControl IFrame1; Then, you need to do findcontrol to identify the control on the page and typecast it: HtmlControl IFrame1 = (HtmlControl)this.FindControl("IFrame1"); Now you can access the src property: IFrame1.Attributes["src"] = http://www.live.com ; I tried this solution but it did not work. Cry SimilarlyI found many other solution saying exactly the same thing which I mentioned above. I posted on different forums and the answer was that this solution might not work if you are using master pages. And they gave me another suggestion that instead of passing IFrame1 (i.e. the ID of your Iframe) just pass the client ID of the IFrame to Findcontrol. But that solution also did not work for me. Then I came across a POST which stated that turn your HTML snippet into server side code and then use the above code i.e. (HtmlControl IFrame1 = (HtmlControl)this.FindControl("IFrame1");) I did not try this suggestion, instead I only turned my IFrame into a server side control by adding a runat="server" attribute into my IFrame and then like any other server control I accessed my IFrame from the code behindLaughing I hope that this will help all who are facing same kind of problem. Here is the summary: * Turn your IFrame into a server side control by adding a runat="server" attribute, like this: <IFrame id="myDynamicFrame" scrolling="auto" runat="server"/> * Now you can access this control from your code behind file and you can set its src property on the fly, like this: myDynamicFrame.Attributes["src"] = "http://www.shahidriaz.com";


Kicked By:
Drop Kicked By: