Solved

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

Posted on 2011-03-08
7
377 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

706 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

19 Experts available now in Live!

Get 1:1 Help Now