Click here to Skip to main content
15,919,749 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

I have a button in a page, on clicking this button, a pop-up opens up(the pop-up is also an aspx page). After some action is performed in the pop-up, it is closed by using window.close(). Now after this pop-up is closed, I want to refresh the main page (in which the button is placed). How can I do this in Javascipt? Can anyone help me?

Thanks in advance.
Posted
Updated 13-Jul-17 21:12pm
Comments
Sunasara Imdadhusen 28-Oct-10 2:27am    
Do you want to refresh parent page when closing it's child?

Just add this code right after the code for opening the pop up.

window.location.reload;

It will solve your problem for sure.
 
Share this answer
 
Comments
Dalek Dave 28-Oct-10 3:45am    
Good Answer.
Sunasara Imdadhusen 28-Oct-10 4:25am    
This will executing when popup was opened, am i right?
But the requirement is he want to refresh a page after clicking on close.
Lokesh Zende 28-Oct-10 5:54am    
It will work.
Hi,

This is solution(this function is refresh parent window and close popup window as well).

C#
function closePopupWindow(){
   window.opener.location.reload();
   window.close();
}



Please do let me know, if you have any doubt.

Please provide "Vote" if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Thanks,
Imdadhusen
 
Share this answer
 
Comments
bedathur_ganesh 28-Oct-10 2:40am    
Thanks for the help. I tried this, but the problem with this is , once the parent page reloads, the pop-up is again opened. How can I make that the pop-up is not to opened?
Sunasara Imdadhusen 28-Oct-10 2:41am    
Are you open a popup window using server side or client?
bedathur_ganesh 28-Oct-10 5:59am    
I am using window.open() in client side.
Atlapure Ambrish 14-Jul-17 3:35am    
Are you using onload event to open the popup?
HTML
//for example you have two pages i.e.  page1.aspx and page2.aspx
//and you want refresh page1.aspx through page2.aspx then
//add this code in page2.aspx page in aspx region







<script type="text/javascript">
       
        function RefreshParent() {

            //if (window.opener != null && !window.opener.closed) {

                window.opener.location.href = "page1.aspx";

                //self.close(); //code for page2.aspx close
            //}
        }
        window.onbeforeunload = RefreshParent;
   
    </script>



C#
//and add in page2.aspx.cs page, where you want to this activity,Means on button //click or other control event





  ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "RefreshParent();", true);
 
Share this answer
 
Comments
Richard Deeming 14-Jul-17 9:41am    
SEVEN YEARS too late.
Shantilal Suthar 1-Oct-19 7:19am    
This is not working for me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900