Link to home
Start Free TrialLog in
Avatar of ayha1999
ayha1999

asked on

Error: 'opener.document' is null or not an objectQuestion:

The above error occurs when I click a hyperlink on a child window. How can I solve the problem?

<input onclick="Javascript:window.showModalDialog('Customers.aspx', '', 'dialogWidth:300px;dialogHieight:300px;status=no;scrollbars=no;');"  return false" type="button" value="Pick" />

 <a href="#" onclick="opener.document.forms[0].txtCustId.Text='<%# Eval("Id") %>';opener.document.forms[0].txtName.Text='<%# Eval("Name") %>'; window.close(); return false"> <%# Eval("Id")%></a>

thanks

ayha
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

window.opener does not work when used with showModalDialog I'm afraid, the only thing available is the returnValue that can be set on the child page.
You could pass back some comma seperated values back or something like that :

Otherwise you would have to go back to using window.open

Avatar of ayha1999
ayha1999

ASKER

could u please give me a sample using "returnValue"?

thanks
showModalDialog is not a window the same way window.open is.  So, yeah, window.opener is null.

Check out this page:

http://msdn2.microsoft.com/en-us/library/ms536759.aspx

Use 'dialogArguments' to move do updates and such.
Code for parent page
<script type="text/javascript"> 
function openModalWindow(url, height, width) { 
    var features = 'dialogWidth:' + width + ';dialogHeight:' + height + ';status:no;scrollbars:no;' 
    var rVal = window.showModalDialog(url, "", features); 
    if (rVal != null)
    {
        document.getElementById("mycontrolId1").Value = rVal[0];
        document.getElementById("mycontrolId2").Value = rVal[1];
    }
} 
</script> 

Open in new window


code for child page called from a save button or close button
<script type="text/javascript">
function closeWindow()
{
    var arrReturnVals = new Array(document.getElementById(ctrl1).Value, document.getElelmentById(ctrl2).Value);
    window.returnValue = arrReturnVals;
    window.close();
}
</script>

Open in new window

could you please post the complete script on how to use it on button click and hyperlink?

thanks
ASKER CERTIFIED SOLUTION
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks