Search code examples
c#asp.netpostbackpopupwindowcross-page-posting

How to make previous page refresh after I click a button in pop-up window?


My main page has a GridView and Buttons for add/update. When I click the update button, a window pops up(used JavaScript) which has input fields and a Button for actually updating the record. What I want to know is how to refresh the main page when I click the update button inside the pop-up window.

This is the partial code of what I tried on actual update's OnClick:

if (PreviousPage != null)
            {
                GridView gridv = (GridView)Page.PreviousPage.FindControl("GridView1");
                gridv.DataBind();
            }

While debugging, I realized that the if statement was never executed. Does that mean pop-up windows do not have a PreviousPage initially? If so how can I reach the Main page then? (i shall note that the main page is not a master page)

This is how I create the pop-up on button click from the Main page(so it's a new window):

function btnEditEP_Click() {
            var recID = document.getElementById('<%=tboxEdit.ClientID%>').value;
            window.open("editPopupEP.aspx?Txt=" + recID, "_blank", "toolbar=yes", "resizable=yes", "scrollbars=yes");
        }

Solution

  • On your child window you can call a function something like this in your child window call on your update function

    <script type="text/javascript">
            function MyFunction() {
    
                window.opener.PostBackParentWindow();
                window.close();
            }
      </script>
    

    and in your parent window call add this code

      <script type="text/javascript">
     function PostBackParentWindow() {
    
                __doPostBack(null, null);
            }
    </script>
    

    Hope it might help