Passing Parameters BACK from a WebDialog

I have always figured out some “not so pleasant” work arounds to pass something back from a WebDialog to the underlying WebPage.

I found this referenced that does seem to work when one WebPage opens a single WebDialog that it contains:
https://forum.xojo.com/38460-web-dialog-and-self

BUT it does NOT work if you have a WebPage that contains WebDialog1 which contains WebDialog2 and you want to pass something back from WebDialog2.

I want to pass something back from Webdialog2 back to Webdialog1. I can “hard code” the reference in WebDialog2 back to WebDialog1
** BUT **
If I want to use this “two layer” dialog on different WebPages then it gets ugly since I now need to “condition” different statements on where to pass back the data.

I have sometimes created a Session Parameter that all WebPages and WebDialogs can reference and passed data that way. I know an ugly “GLOBAL” of sorts.
BUT
if I want to take any action on the WebDialog1 where I am returning from WebDialog2 (Like Call a Method to process the data I want to return) and WebDialog1 is used in multiple pages that also gets very ugly.

Any cleaner suggestions?

subclass webdialog, add a returnfield property in this subclass
and make webdialog1 and 2 a subclass of this above subclass of webdialog.
then they will behave the same, independantly of where they are called from.

in the calling page or container, define a handler method for the dismissed event of the webdialog. Use this method to pass data from the webdialog.

In the calling method or event, insert the addhandler statement. In the handler method, just before exiting it, do not forget the removehandler.

This works very well and avoids all the ugly global parameters. It will also work between 2 webdialogs. Any webdialog to the parent.