Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to refresh parent window when child window in closed?

Posted on 2011-02-14
12
Medium Priority
?
1,235 Views
Last Modified: 2012-05-11
I opening my pop up in parent window on link button click

PARENT window code to open child window

Public Shared Sub OpenPopUp(ByVal response As HttpResponse, ByVal url As String, ByVal target As String, ByVal windowFeatures As String)
        If (String.IsNullOrEmpty(target) OrElse target.Equals("_self", StringComparison.OrdinalIgnoreCase)) AndAlso String.IsNullOrEmpty(windowFeatures) Then
            response.Redirect(url)
        Else
            Dim page As Page = CType(HttpContext.Current.Handler, Page)
            If page Is Nothing Then
                Throw New InvalidOperationException("Cannot redirect to new window outside Page context.")
            End If
            url = page.ResolveClientUrl(url)
            Dim script As String
            If (Not String.IsNullOrEmpty(windowFeatures)) Then
                script = "window.open(""{0}"", ""{1}"", ""{2}"");"
            Else
                script = "window.open(""{0}"", ""{1}"");"
            End If
            script = String.Format(script, url, target, windowFeatures)
            ScriptManager.RegisterStartupScript(page, GetType(Page), "Redirect", script, True)
        End If
    End Sub

Protected Sub lBtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lBtn.Click
            OpenPopUp("Child.aspx", "recipients", "width=800,height=700,status=0,menubar=1,toolbar=0,location=0,scrollbars=0")
      End Sub

It is working perfectly fine.
I do not have any issue with this code. I would prefer to keep it this way.

CHILD window code
I am using ASP.Net button on the child window.Since I have to implement some functionality on code behind of this button.

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
       /// CODE
              Page.ClientScript.RegisterStartupScript(Me.GetType(), "close", "Done();", True)          
      End Sub

ASPX code

<script language="javascript" type="text/javascript">
        function Done() {
            window.close();
        }
        </script>
Now my question is how do I refresh my Parent window when my child window is closed?
0
Comment
Question by:AppDevs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 27

Expert Comment

by:Shaun Kline
ID: 34888755
Before the window.close() function on your child page, you could add:

window.opener.location.reload(true);

or something similar. There are numerous ways to reload a page, as seen here: http://www.mediacollege.com/internet/javascript/page/reload.html
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34888756
This logic works for me.
This javascript code will load a popup and will check in intervals whether it is closed or not. Once found closed, it will refresh the parent page.
// Javascript Code

 <script type="text/javascript" language="javascript">
        var int;
       
        function redirect()
        {
            location.href='Parentpage.aspx';
        }
       
        function openWin(mypage, myname, w, h,scroll,resize)
            {
                int=self.setTimeout("checkWin()",1000);
                  var winl = (screen.width - w) / 2;
                  var wint = (screen.height -h) / 2;
                  winprops ='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resize+',status=1'
                  myWindow = window.open(mypage, myname, winprops)
                  if (parseInt(navigator.appVersion)>= 4)
                  { myWindow.window.focus(); }
            }

        function checkWin()
        {
            if (myWindow.closed)
            {
                redirect();
            }
            else {
               int=self.setTimeout("checkWin()",1000);
            }
        }

    </script>



// C# Code
 private void PopupTargetWindow(string PopupWindow)
    {
        string strjscript = "<script language='javascript'>";
        strjscript += "openWin('" + PopupWindow + "','','800','400','yes','no');";
        strjscript += "</script" + ">";
        RegisterStartupScript("Target", strjscript);

    }
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34888774
Another issues I faced someother approaches is that, when parent page is reloaded - the last function will be executed.

For eg:- Since the last action is opening popup, when close popu and reload parent page - it again loaded the same popup!

Anyway I finally acheived in this way.

Raj
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:AppDevs
ID: 34888995
RajkumarGS:
Child window is closing perfectly, but the data in the parent is not updated.
For example, I am updating Phone number in the child window, when the child window is closed, I want the phone number in the parent window to be updated. how do I do it?
0
 

Author Comment

by:AppDevs
ID: 34889006
and also I want to retain all the entries I made in the parent window, before I opened the child window.
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34889142
When you close popup, is the parent window refreshes ?
If yes, check whether the code inside
If (!IsPostBack)
{
}
is executing ?
0
 

Author Comment

by:AppDevs
ID: 34889355
It is going into the loop and reloading the page.
how do make it retain the previous selection and entries and display the updated information on the parent page.
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34889501
Can you try the suggestion here
http://p2p.wrox.com/html-code-clinic/5034-pop-up-close-refresh-parent.html

Instead of this
  location.href='Parentpage.aspx';

The alternative solution, that I know - need some more effort. So first try this and let me know
0
 

Author Comment

by:AppDevs
ID: 34889710
I tried it, it is not working.
0
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 2000 total points
ID: 34889758
Alternative solution is - Store the values somewhere before load popup and when parent page is reloaded, you need to restore from that temporary storage. It could be using SessionState, QueryString, ViewState OR using temporary tables in database.

For this case, you need to modify this line in javascript, by adding some querystring value
location.href='Parentpage.aspx';
to
location.href='Parentpage.aspx?IsBack=1';
This is to identify whether the page is reloaded from popup.

If Page_Load, you need to check whether IsBack querystring has value=1. Then load values from the storage which you preferred.

In one of my very old project in ASP.Net, I done the same thing using QueryString. In datagrid there is one textbox for each row. I passed these textbox values as comma separated to popup as querystring and passed back.

Raj
0
 

Author Closing Comment

by:AppDevs
ID: 34891079
It is working, Thank you.
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34893401
Glad I could help!

Which option you choosed?

Raj
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

715 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