Question

I have a popup window, which will search for items from a grid. It returns value to the parent page, when a row is selected directly. But if i search the grid by button click and select a row, the parent page receives undefined object, although the correct values are returned from the popup. How can the parent page receive the correct values?

Était-ce utile?

La solution

OP did mention this in a comment on the question, but to make it clear: this answer is a copy of this one by user ConnorsFan. If the answer is updated, that's likely where any updates will appear.


In order to keep using showModalDialog in my page, I had to come up with my own workaround for the bug. So, here it is...

In Google Chrome, after a postback, showModalDialog always returns undefined. However, the window.opener property in the modal dialog points to the caller window, even after postbacks. So, I thought about putting the result of the dialog in the returnValue property of that caller window. And it works.

In the caller window:

var prevReturnValue = window.returnValue; // Save the current returnValue
window.returnValue = undefined;
var dlgReturnValue = window.showModalDialog(...);
if (dlgReturnValue == undefined) // We don't know here if undefined is the real result...
{
    // So we take no chance, in case this is the Google Chrome bug
    dlgReturnValue = window.returnValue;
}
window.returnValue = prevReturnValue; // Restore the original returnValue

At this point, use dlgReturnValue for further processing In the modal dialog window:

if (window.opener)
{
    window.opener.returnValue = dateValue;
}
window.returnValue = dateValue;
self.close();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top