2 Replies - 2938 Views - Last Post: 14 October 2011 - 09:34 AM

#1 arvindthakur  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 133
  • Joined: 07-June 11

How to call a method in parent object from a showModalDialog

Posted 13 October 2011 - 03:35 AM

hello Guys,

I have defined a method in an iframe named as refresh1().In the iframe we are showing records in a table.
on clicking a record of table or you can say row a showmodal Dialog object will open which shows the info of clicked record.I want to call refresh1() method onclick of save button whic is defined in modal dialog.I have tried parent.window.dialogArguments.refresh1() but it is not workin.

Thanks

Arvind

Is This A Good Question/Topic? 0
  • +

Replies To: How to call a method in parent object from a showModalDialog

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5630
  • View blog
  • Posts: 12,078
  • Joined: 02-June 10

Re: How to call a method in parent object from a showModalDialog

Posted 14 October 2011 - 06:57 AM

That is in NO WAY the right way to do it.
One class should not reach into another and order it to run a specific method. It should raise and event. The listening class (the parent) then hears that event and reacts as it is programmed to (do refresh or whatever).

The keeps both classes un-tightly bound to the other. They are black boxes that don't try to control each other. This is an important principal in OOP.

I know the tutorial here is not in JS, but the explanations are valuable to getting a richer understand of the concepts. From there I'm sure you can find a couple event tutorials in JS and it will all make sense.

See FAQ #2


FAQ (Frequently Asked Questions - Updated Sep 2011

Spoiler

Was This Post Helpful? 1
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4404
  • View blog
  • Posts: 12,260
  • Joined: 18-April 07

Re: How to call a method in parent object from a showModalDialog

Posted 14 October 2011 - 09:34 AM

Take a look at window.opener. From your popup, you can get access to the parent window using window.opener and then from there call the javascript function on the parent. Be sure to always check that window.opener is not null first because if the person closes the parent, it will no longer exist and you can't call its function.


:)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1