Override Dialog close event

Override Dialog close event


Hi, another newbie with a question i'm afraid
I've got a problem trying to override the close event on Dialog ,
here's the scenario
I have a dialog showing an Iframe. when the user closes the dialog I
want to execute some teminiation code on the page in the iframe, which
includes interaction on whether to save data etc and so takes some
time
What I want to happen is that when close is clicked my function to
initiate that teminate code is called (I have hooked up the
beforeclose event and this works fine) but I don't want the dialog to
actually close until the content page sends a callback that it's
termination is complete and that it the bit I can't make happen
I think this is because even though my function returns false the test
in close of
if (false === this._trigger('beforeclose', event))
always returns true so the dialog completes the close event regardless
I've got a bit stuck so any thoughts gratefully recieved!
here's the gist of my code
function showDePopup(){
var options = {
     beforeclose: function(){_onDataEntryPopupCloseButtonClick();}
$j("#popupDiv").dialog(options);
}
function _onDataEntryPopupCloseButtonClick()
{
var dataEntryGroup = $j("#popupDiv")
[0].contentWindow.PageComponentManager.get_DataEntryGroupComponent();
dataEntryGroup.Cancel();
return false
}
//dataEntryGroup.Cancel should call _closeDataEntryPopup when complete
but never does
function _closeDataEntryPopup()
{
$("#popupDiv").dialog('option', 'beforeclose', function()
{true;});
$j("#popupDiv").dialog('close');
$j("#popupDiv").remove();
}