Clear IFRAME from code behind?

G

Guest

I have a ASP.Net page with an IFrame control.
I need to make it empty from code behind.
Is it possible?
 
G

Guest

I tried that as my first suggestion, but it didn't work.

The serverside control has no src property.
It is possible to find the HTML src attribute by the Attributes collection,
but it is always set to empty string and it makes no difference to change it.

I tried everything: InnerText, InnerHTML, DataBind, etc.
 
B

Barrie Wilson

Peter Bromberg said:
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 ;


but to "clear it" I believe it should be:

IFrame1.Attributes["src"] = "about:blank";
 
S

Steven Cheng[MSFT]

Yes, another means is use a static black htm page and always let the iframe
point to that page whenever you want to make it display empty.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
From: "Barrie Wilson" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Re: Clear IFRAME from code behind?
Date: Wed, 14 Nov 2007 11:54:55 -0600

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 ;


but to "clear it" I believe it should be:

IFrame1.Attributes["src"] = "about:blank";
 
G

Guest

I actually did all of this correct from the beginning.
The reason I did not get the expected result was that I had a couple of AJAX
UpdatePanels and the IFRAME was not covered by the UpdatePanel that was
changed .....
Sorry for that, and thanks again for your feedback!
 
G

Guest

Previously I used an empty HTML file or did manual wiping of the result.
The "about" solution is much more elegant!
Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top