barsan
barsan

Reputation: 2491

How to refresh parent page on closing of Pop Up Window

I have two ASPX pages. In first page I am showing the Grid with values from database and on the second page I am showing as pop-up window where user can see another gridview and they can add member from this page. After they add member from Pop-Up window and close then my requirement is to refresh the first page so that its grid reloads the new added members on its gridview. Can anyone help me on this? I am trying this following code but this is not helping:

    function refreshParent() {
        window.opener.location.href = window.opener.location.href;

        if (window.opener.progressWindow) {
            window.opener.progressWindow.close()
        }
        window.close();
    }

  <body onunload="refreshparent();">

And another problem is as I am using one more server side button on pop-up window so whenever the button is pressed the window closes and refresh the parent page. But i want the pop-up to be closed by the user input.

Your help would be so appreciable.

Thanks

Upvotes: 1

Views: 32363

Answers (3)

user13741760
user13741760

Reputation: 11

<button onclick="CloseAndRefresh()" class="close-btn">&times;</button>

<script>
//close popup window and refresh the parent window
function CloseAndRefresh()
{
   window.history.back(); //This will refresh parent window.
   window.close();//Close popup window. You may also use self.close();
}
</script>

Upvotes: 1

Abdul
Abdul

Reputation: 2120

Under your close button, you can add this code

 Response.Write("<script language=JavaScript>  opener.location.reload(); </script>")
 Response.Write("<script language='javascript'> { window.close();}</script>")

Upvotes: 0

Chirag Vidani
Chirag Vidani

Reputation: 2587

You can go ahead with below code:

Parent page

HTML

<script type="text/javascript">
    function OpenPopup() {
        window.open('ChildPopupWindows.aspx', '', 'width=200,height=100');            
    };
</script>

<input type="button" value="Open popup" onclick="javascript: return OpenPopup()" />

Child page

HTML

<script type="text/javascript">
    function CloseWindow() {
        window.close();
        window.opener.location.reload();
    }
</script>

<asp:Button ID="btnServer" runat="server" OnClick="btnServer_Click" Text="Request server" />
    <br />        
    <input type="button" value="Close Window" onclick="javascript: return CloseWindow();" />

C#

protected void btnServer_Click(object sender, EventArgs e)
    {

    }

Explanation

When you click "Request Server" button, server postback will take place whereas your child window will not be closed.

Your child window will be closed when you click "Close Window" button, this will also refresh your parent page.

Queries welcomed...

Upvotes: 7

Related Questions