How to get a custom coltrol to pass back a value to the it's parent page

K

Kay

Hello,

I have a custom control which contains an IFrame the source of the IFrame is
another application (the Customer app.) which adds a customer record to the
Database. The custom control has been dropped on a web page, when the user
clicks on the custom control it opens up the 'Add New customer page' from
the Customer app. When the user clicks finished on the customer page, a
customer record is added to the Database. I now need to have the CustomerId
of the new record passed back from the Customer app. to the page which
contains the custom control. Does anyone know or have suggestions how I
might achieve this.

Your help would be appreciated,
Thanks,
Kay.
 
A

agapeton

Easy...

Say this is in the <head></head> of your iframe...and btnSubmit is the
asp:Button and lblId is an as:Label on your mainpage....


<script type="text/javascript">
window.onload = function(evt) {
document.getElementById('btnSubmit').onclick = function(evt)
{
alert(parent.document.getElementById('lblId').value);
};
}
</script>

That should do it... now if you are doing controls inside of other
controls, you have either have to do a lot of magic to get the proper
ASP.NET UniqueId or you can set this declaratively.

Put this in your <head></head>

<script type="text/javascript">
function DoStuff( ) {
alert(parent.document.getElementById('lblId').value);

};
</script>

and put this in the page... the "return false;" stops postback so you
will want to remove that if you want postback as well (but that will
definately add more complexity...at that point you need
RegisterClientScriptBlock and more magic)

<asp:Button ID="btnSubmit" runat="server" OnClientClick="DoStuff();
return false;" Text="Click Me!" />

David Betz
http://davidbetz.net/dynamicbliss/
http://davidbetz.net/winfx/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top