简体   繁体   中英

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

My main page has a GridView and Button s 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");
        }

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

On the update click also perform the close pop up call

<script>
var popupWindow;

function openw(url) {
    popupWindow = window.open(url, "popup", "");
}

function closew() {
    if (popupWindow) {
        popupWindow.close();
    }
}

</script>
<a href="javascript:openw('about:blank')">open</a><br />
<a href="javascript:closew()">close</a>

like described here . How to close a popup window in a parent window?

and then in closw you can call your parent page with true/false value depending on your update operation. You can use a hiddenfield for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM