Solved

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

Posted on 2011-03-08
7
381 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…

939 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now