views:

182

answers:

2

I have a page with an iframe like this:

<iframe runat="server" id="rsPrintFrame" src="framedPage.aspx" height="0" width="0"></iframe>

I need to get access to a component on the 'framed' page from the parent page, as one would typically do with $find() or Sys.Application.findComponent(). But obviously I can't simply do: myFrame.contentWindow.document.$find().

I've come up with a work-around involving making the $find() call in the framed page and saving it to a variable accessible to the parent page via javascript.

But is there a straightforward way to call findComponent() from the parent page while targeting a framed page's element/component.

BTW, getElementById() is not an acceptable solution.

A: 

Is something like this what you're looking for?

window.frames['<%= rsPrintFrame.ClientID %>'].document....
Russ Bradberry
Nope, nothing to do with server-side scripting.
Kon
+1  A: 

As far as I know you cannot use the $find from the parent window to find a component in the child window. You can do this however:

var component = myFrame.contentWindow.$find("myComponentId");

If you are using this often you can create a wrapper function.

korchev
How could that possibly work? $find() is just a shortcut for Sys.Application.findComponent().. So I don't think myFrame.contentWindow.Sys.Application.findComponent() is valid.
Kon
If ASP.NET Ajax is loaded in that frame (I assume it is because otherwise the component wouldn't have worked) this should be no problem. Have in mind that $find is the same as window.$find which is the same as window.Sys.Application.findComponent. When dealing with frames (and iframes for that matter) contentWindow is the window of the frame. I hope this helps.
korchev
Well, slap me around and call me Susan... you're right, this worked: myFrame.contentWindow.$find(id)
Kon