Results 1 to 10 of 10

Thread: Problem with .aspx page in an iFrame?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    Problem with .aspx page in an iFrame?

    Hi,

    I have an aspx page in an iFrame, the iframe sits on another aspx page. It is all working well as you would expect. The problem is this, i have a label control on my main page the one the iframe is sitting on, now if i change my label's property in the iframe i can't get it to update the main page. Do i have to do this using sessions and reloading the page or something.

    Any advice greatly appreciated.

  2. #2
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    Re: Problem with .aspx page in an iFrame?

    You MAY be able to use the findcontrol function to find the label in the iframe (not sure if you can in asp.net). If not you could always do like you said and reload the iframe page and use a session varialble or parameter in the url

    good luck

    In the unlikely event that I answer your question correctly, please Rate my post

    Using Visual Studio 2005 Professional

  3. #3
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    Re: Problem with .aspx page in an iFrame?

    You can try this in your page that holds the iframe to find the control

    I havent' tested this yet though.

    VB Code:
    1. Dim iframeLabel As label = CType(iFrameName.FindControl("LabelName"), Label)

    In the unlikely event that I answer your question correctly, please Rate my post

    Using Visual Studio 2005 Professional

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    Re: Problem with .aspx page in an iFrame?

    Hi,

    Thanks for pointing me in the right direction. I wrote the following but it still doesn't work:

    Code:
    HtmlControl getMyiFrame = (HtmlControl)this.FindControl("myiFrame");
    
    //getMyiFrame.Attributes["src"] = "http://www.google.co.uk";
    
    Label myLabel = getMyiFrame.FindControl("Label2") as Label;
    
    if (myLabel != null)
    {
         Response.Write("FOUND - Label");
    
    }
         else
    {
         Response.Write("NOT FOUND - Label");
    }
    I can change change my iFrames attributes but i can not access controls living inside the iframe, such as my Label control??

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    Re: Problem with .aspx page in an iFrame?

    I have managed to change the value of my iFrame's label control by passing in a variable with a value using the iframes SRC attribute:

    Code:
    getMyiFrame.Attributes["src"] = "iFrameTEST_content.aspx?name=" + getText;
    in the iframe i have:

    Code:
    Label2.Text = Request.QueryString["name"];
    This works great. Now i just have to figure out how to do it reverse, so from my iFrame change a label control living on my main page?

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: Problem with .aspx page in an iFrame?

    Since the IFRAME is a container inside the top-level page, you want to use javascript in the child page to modify a property on the parent page, and then force the parent page to postback (or just modify it directly).

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    Re: Problem with .aspx page in an iFrame?

    How will the Javascript in the container page talk to the top level page, my javascript isn't top notch so could you give me some pointers or even some basic code if you have it handy please?

    Thanks.

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: Problem with .aspx page in an iFrame?

    window.parent.(document?).getElementById('hiddenfield1').value = 'sdklfajasdlfkjas';

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    Re: Problem with .aspx page in an iFrame?

    Thanks, i will give this a go.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    Re: Problem with .aspx page in an iFrame?

    I think i messed this up, i can't get it to work?

    I have the following code in my iframe .aspx page :

    Code:
     <script type="text/javascript">
        
        function PageInit()
        {
         window.parent.document.getElementById('MyLabelonContainerPage').Value = "hello";
        }    
        
    </script>
    Code:
    <body  onload="PageInit()">
    Please help!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width