PDA

View Full Version : Refresh Parent window on close of Popup window



samijsr
09-02-2011, 10:21 AM
1) Script Title: DHTML WINDOW WIDGET(v1.1)

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/index.htm

3) Describe problem:

The Popup window is working perfect as I want in my ASP.Net page
I want to refresh Parent window on close of the Popup.

_dopostBack is also working but, I need to refresh the whole page as Popup window is adding/removing run time Textbox in parent window.

As the code is using iframe to generate popup window.opener is not working.

jscheuer1
09-02-2011, 10:39 AM
If I understand you correctly:


window.opener.parent.location.reload();

Or possibly:


parent.location.reload();

samijsr
09-02-2011, 10:50 AM
Hi John

I have tried all those

window.opener.location.reload()
and also
parent.location.relaod()

window.opener.location.href='"default.aspx"

but those all not working get the error message

window.opener is null or not ab object

same for all if change to parent.location

jscheuer1
09-02-2011, 10:52 AM
Then I would have to see the page.

Please post a link to a page on your site that contains the problematic code so we can check it out.

samijsr
09-02-2011, 11:24 AM
Hi John

the script is dhtmlmodal.htm

http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/dhtmlmodal.htm

the page is running for local Intranet and behind the firewall so cant link here.

Any way I have tested the simple java code to open popup window, with that
window.opener.location.reload() is working perfectly.

but when I call dhtmlwindow.open

call the below function in Button_onclcik()
here some code to save data in database.

response.write("<script>window.opener.location.reload();</script>");
response.write("<script> parent.emailwindow.hide();</script>");

its not working and get error window.opener is null or not an object

jscheuer1
09-02-2011, 02:12 PM
Does the emailwindow load onload of the parent window? If so reloading the parent will reload the emailwindow. If not, reloading the parent will have the effect of dismissing the emailwindow. It won't be there any longer because it depends upon the parent to exist. If the former, you will have to rethink your approach. If the latter, and the emailwindow is in fact an iframe, and it's page is on the same domain as the parent, all you need is:


response.write("<script>parent.window.location.reload();</script>");

However, just writing out a script like that to a page might not bring the desired result anyway. It has to execute. But from what you're saying, from the error you're getting, it sounds like it is executing.

samijsr
09-05-2011, 12:12 AM
Hi John,

Here is the code which I use
<script type="text/javascript">
function openaddproject() {
addprojwindow = dhtmlmodal.open('ProjBox', 'iframe', 'AddProject.aspx', 'Add Project with Job/MM/MS Code', 'width=750px,height=500px,center=1,resize=0,scrolling=0')
addprojwindow.onclose = function() { //Define custom code to run when window is closed
var theform = this.contentDoc.forms[0] //Access first form inside iframe just for your reference
return true

}
}

</script>

calling the function through hyperlink.

<a href="#" onClick="openaddproject(); return true"><span class="bluelink1">Add Project</a> </span><span id="addproject" style="color: red"></span>


Now at the Button click event which first save the data at end i have this code

Response.Write("<script>window.opener.location.reload();</script>");
Response.Write("<script>parent.addprojwindow.hide();</script>");
Response.Write("<script>parent.addprojwindow.close();</script>");

jscheuer1
09-05-2011, 05:21 AM
Change this:


Response.Write("<script>window.opener.location.reload();</script>");
Response.Write("<script>parent.addprojwindow.hide();</script>");
Response.Write("<script>parent.addprojwindow.close();</script>");

to:


Response.Write("<script>parent.window.location.reload();</script>");

That should at least reload the top page. If you still need those others, then they have to be done first:


Response.Write("<script>parent.addprojwindow.hide();</script>");
Response.Write("<script>parent.addprojwindow.close();</script>");
Response.Write("<script>parent.window.location.reload();</script>");

I'm just going by your word that you get an error, which should mean that the code is actually getting executed, or is attempting to execute.

If you want more help:

Please post a link to a page on your site that contains the problematic code so we can check it out.