Accessing a Control on Parent Page from a page inside IFrame

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • irfan2irfan
    New Member
    • Apr 2008
    • 2

    Accessing a Control on Parent Page from a page inside IFrame

    Hi,
    I am trying to access a TreeView Control from IFrame containing B.aspx.

    So the TreeView control is on the Parent page that contains the IFrame with B.aspx. From B.aspx (Iframed) i want to access TreeView control on the Main page.

    Is there any way to get it done via Java Script?? Its driving me nuts...

    I am using VS2005...

    PS: I don't want to use Content Place Holder instead of IFrame for some reason.

    Any help would be really appriciated.

    Regards,
    Faani
  • irfan2irfan
    New Member
    • Apr 2008
    • 2

    #2
    Accessing a Control on Parent Page from a page inside IFrame

    I have a TreeView control and an IFrame on Page A.aspx. The IFrame have page B.aspx inside it.

    I have a button on page B.aspx, when its clicked I want to access TreeView on Page A.aspx which is the parent page of IFrame(B.aspx). ..

    I think its possible with some kind of Java script like;

    <asp:Button id="Button1" runat="server" OnClick=" 'parent.documen t.getelementbyI d("myTree").Exp andAll()'" />

    but its giving me errors
    - Expression expected.

    if I remove runat="server" tag from the Button1 control, the page runs but the button disappears.

    anyone plz help...

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      I've split your post in another thread and merged with this one.

      Note that JavaScript is case-sensitive, so document.getele mentbyId("myTre e") should be document.getEle mentById("myTre e").

      Comment

      • pronerd
        Recognized Expert Contributor
        • Nov 2006
        • 392

        #4
        Originally posted by irfan2irfan
        i want to access TreeView control on the Main page.

        Is there any way to get it done via Java Script?? Its driving me nuts...
        I do not think so. iFrames are not current pages tree structure in the way normal frames are. So I do not think they can be accessed, or that the iFrame can access anything outside of it self. This restriction is intentional for security issues.

        You could have the iFrame send a call though AJAX to the server, and have the server then send a call though AJAX to the parent page, but this would be extremly complicated since you would need a listener running in the parent page.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by pronerd
          I do not think so. iFrames are not current pages tree structure in the way normal frames are. So I do not think they can be accessed, or that the iFrame can access anything outside of it self. This restriction is intentional for security issues.
          It can't access or be accessed if it's from a different domain. If it's from the same domain, then there's no problem.

          Comment

          Working...