Solved

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

Posted on 2011-03-08
7
393 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:ayha1999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 35070637
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

0
 
LVL 7

Author Comment

by:ayha1999
ID: 35070666
could u please give me a sample using "returnValue"?

thanks
0
 
LVL 2

Expert Comment

by:cookiej
ID: 35070756
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:Paul Jackson
ID: 35070840
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

0
 
LVL 7

Author Comment

by:ayha1999
ID: 35070864
could you please post the complete script on how to use it on button click and hyperlink?

thanks
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 250 total points
ID: 35071217
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(<%=txtCustId.ClientId%>).Text = rVal[0];  
        document.getElementById(<%=txtName.ClientId%>).Text = rVal[1];  
    }  
}   
</script>

<input onclick="Javascript:window.openModalWindow('Customers.aspx', 300px,300px');"  return false" type="button" value="Pick" />

Open in new window


Child Page:
<script type="text/javascript">  
function closeWindow()  
{  
    var arrReturnVals = new Array(<%# Eval("Id")%>, <%# Eval("Name")%>);  
    window.returnValue = arrReturnVals;  
    window.close();  
}  
</script> 

<a href="#" onclick="closeWindow()"></a>

Open in new window

0
 
LVL 7

Author Closing Comment

by:ayha1999
ID: 35083179
thanks
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question