Clear IFRAME from code behind?

Discussion in 'ASP .Net' started by =?Utf-8?B?SmFrb2IgTGl0aG5lcg==?=, Nov 14, 2007.

  1. I have a ASP.Net page with an IFrame control.
    I need to make it empty from code behind.
    Is it possible?
     
    =?Utf-8?B?SmFrb2IgTGl0aG5lcg==?=, Nov 14, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Nov 14, 2007
    #2
    1. Advertising

  3. 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.
     
    =?Utf-8?B?SmFrb2IgTGl0aG5lcg==?=, Nov 14, 2007
    #3
  4. 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.
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Nov 14, 2007
    #4
  5. "Peter Bromberg [C# MVP]" <> wrote in message
    news:...
    > 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";
     
    Barrie Wilson, Nov 14, 2007
    #5
  6. 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:...
    >> 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";
    >
    >
    >
     
    Steven Cheng[MSFT], Nov 15, 2007
    #6
  7. 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!
     
    =?Utf-8?B?SmFrb2IgTGl0aG5lcg==?=, Nov 15, 2007
    #7
  8. Previously I used an empty HTML file or did manual wiping of the result.
    The "about" solution is much more elegant!
    Thanks!
     
    =?Utf-8?B?SmFrb2IgTGl0aG5lcg==?=, Nov 15, 2007
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    591
    Alphonse Giambrone
    Jun 28, 2003
  2. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    490
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
  3. David

    Response.Clear() doesn't clear

    David, Jan 31, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    1,038
    Mark Fitzpatrick
    Jan 31, 2008
  4. InvalidLastName

    Unrecognized element 'add' after <clear></clear>

    InvalidLastName, Feb 26, 2007, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    971
    Steven Cheng[MSFT]
    Mar 6, 2007
  5. Daedalous
    Replies:
    3
    Views:
    711
    Daedalous
    Jan 16, 2004
Loading...

Share This Page