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?
Asked
Active
Viewed 1,859 times
0
-
I just found out it works fine in IE but this prob occurred in chrome – JaseemAmeer Jan 22 '13 at 06:02
-
I presume you mean ASP.NET? Please show how you do modal. – John Saunders Jan 22 '13 at 06:09
-
http://stackoverflow.com/questions/10213530/javascript-showmodaldialog-not-returning-value-in-chrome this one worked for me – JaseemAmeer Jan 22 '13 at 07:01
1 Answers
0
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();

Community
- 1
- 1

JaseemAmeer
- 107
- 2
- 15