开发者

Populate a user control from a containing frame

I have a troubling task. I have a page contained within an outer frame, on the outer frame is a user control which i need to populate with some data from within the cont开发者_运维百科aining page. The problem is the outer frame is rendered before i can get hold of the required data. How can i accomplish this?


I would use a JavaScript to accomplish this. You can put a Populate method in JavaScript in the parent page with whatever signature you want.

function PopulateControls(param1, param2, param3) 
{
    document.getElementById('<%=this.Control1.ClientID%>');.value = param1;
    document.getElementById('<%=this.Control2.ClientID%>');.value = param2;
    document.getElementById('<%=this.Control3.ClientID%>');.value = param3;
}

Then in the child frame, make sure the page has a built in JavaScript to pass it back up.

window.onload=SendToParent;

function SendToParent() 
{
   window.opener.PopulateControls('<%=this.Field1.ClientID%>','<%=this.Field2.ClientID%>',<%=this.Field3.ClientID%>');

}

You might have to tweak the code above, but the gist is that the parent page controls will end up waiting until the child page is fully loaded before it's done. If you want to use labels and whatnot, you can use the InnerHTML property on divs instead.


Couldn't you just create a public Populate sub in your user control and call it from the outer frame when required data is loaded? Populate would take the data as arguments and populate the control with this data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜