Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Clear IFRAME from code behind?

Reply
Thread Tools

Clear IFRAME from code behind?

 
 
=?Utf-8?B?SmFrb2IgTGl0aG5lcg==?=
Guest
Posts: n/a
 
      11-14-2007
I have a ASP.Net page with an IFrame control.
I need to make it empty from code behind.
Is it possible?

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      11-14-2007
Yes, if you set the IFRAME as runat="server". You then have access to it from
codebehind, and you can set the src property.

--Peter
http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com



"Jakob Lithner" wrote:

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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmFrb2IgTGl0aG5lcg==?=
Guest
Posts: n/a
 
      11-14-2007
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.
 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      11-14-2007
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 ;


Have fun,
--Peter
http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com



"Jakob Lithner" wrote:

> 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.

 
Reply With Quote
 
Barrie Wilson
Guest
Posts: n/a
 
      11-14-2007

"Peter Bromberg [C# MVP]" <> wrote in message
news:A5E0463F-7948-4469-950C-...
> 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";


 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      11-15-2007
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" <>
>Newsgroups: microsoft.public.dotnet.framework.aspnet
>Subject: Re: Clear IFRAME from code behind?
>Date: Wed, 14 Nov 2007 11:54:55 -0600
>
>"Peter Bromberg [C# MVP]" <> wrote in

message
>news:A5E0463F-7948-4469-950C-...
>> 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";
>
>
>


 
Reply With Quote
 
=?Utf-8?B?SmFrb2IgTGl0aG5lcg==?=
Guest
Posts: n/a
 
      11-15-2007
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!
 
Reply With Quote
 
=?Utf-8?B?SmFrb2IgTGl0aG5lcg==?=
Guest
Posts: n/a
 
      11-15-2007
Previously I used an empty HTML file or did manual wiping of the result.
The "about" solution is much more elegant!
Thanks!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use an iframe as a link (make the whole iframe clickable) mi HTML 4 05-21-2008 10:13 PM
Response.Clear() doesn't clear David ASP .Net 2 01-31-2008 08:32 PM
Unrecognized element 'add' after <clear></clear> InvalidLastName ASP .Net Web Services 3 03-06-2007 03:07 AM
Targeting a parent iframe from a sub-iframe albanitus@yahoo.com HTML 0 11-15-2006 04:40 PM
Get form values from iframe (1) to iframe (2) inside a layer in iframe (1) Daedalous Javascript 3 01-16-2004 11:08 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57