0

I have aspx page that has a gridview in which there is an update button. when I click update button a pop up window opens. The second aspx page (pop up windows) has fields a delete button. when I click the delete button the second aspx page close and the row is deleted from the gridview in the first aspx page. I'm not able to see the row has been deleted from the gridview until i refresh manually the page.

How can I refresh the parent page(the page that has the gridview) right after closing the second page (the pop up window page)?? I tried this but didn't work :

Response.Write("<script>window.close();</" + "script>");
Response.Write("<script>window.opener.location.reload();</" + "script>");
  • See : https://stackoverflow.com/questions/1318006/reload-parent-window-from-child-window – Robin Camus Jul 28 '17 at 13:42
  • Write code instead of URl it will be help ful. – Ravikumar Jul 28 '17 at 13:47
  • You may want to take a look at `window.postMessage` I think that will be much better solution – serdar.sanri Jul 28 '17 at 13:53
  • Why are you bothering with popup windows at all? Users hate those, and so do popup blockers. Just open a modal or dialog within your webpage. – mason Jul 28 '17 at 14:06
  • You can use window.parent.location.reload() – hsj Jul 28 '17 at 14:09
  • I tried URI and window.parent.location.reload() and still I have to refresh the parent page manually. I tried after closing the pop up window redirect to the parent page that worked but the refreshed parent page was refreshed inside the pop up window. How can I refresh the parent page after closing the pop up window. I used this code: Response.Write(" – ITDeveloper Jul 28 '17 at 14:18

1 Answers1

0

You can use window.opener in the pop up window, just add

window.opener.location.reload();

in pop up window on onbeforeunload or onunload event. but that won't work on chrome, it works on firefox.

Another work around you can use setInterval to check if pop up window is closed or not in the main page:

var page = null;
function openPopUp() { 
    page = window.open("desiredPage.html","windowName", "width=200,height=200"); 
    setInterval(function() {
        if(page != null && page.closed) {
            window.location.reload();
        }
    }, 1000);
}

Second solution works on all browsers.

Niroda
  • 320
  • 1
  • 3
  • 13
  • I added this js code in aspx page: function close() { var page = null; function openPopUp() { page = window.open("popupPageName.aspx","windowName"); setInterval(function () { if (page != null && page.closed) { window.location.reload() } }, 100); } and I did this c# code: Response.Write(""); the pop up window close but it doesn't refresh the parent page after closing – ITDeveloper Jul 28 '17 at 15:42
  • I'm not familiar with aspx but you copied the code I provided in another function which means when you execute `close` function, `openPopUp` won't be executed. Take a look at [jsfiddle](https://jsfiddle.net/m3qupvwe/) I created a simple button when you click on it, a new pop up window 'll open and the button text 'll be changed to Test, when you close pop up window the button 'll get the old value which means the page reloaded :) – Niroda Jul 28 '17 at 16:58