1

我有两个 ASPX 页面。在第一页中,我显示了带有数据库值的网格,在第二页上,我显示为弹出窗口,用户可以在其中看到另一个 gridview,他们可以从此页面添加成员。在他们从弹出窗口添加成员并关闭之后,我的要求是刷新第一页,以便其网格在其网格视图上重新加载新添加的成员。谁可以帮我这个事?我正在尝试以下代码,但这无济于事:

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

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

  <body onunload="refreshparent();">

另一个问题是我在弹出窗口上使用了一个服务器端按钮,所以每当按下按钮时,窗口就会关闭并刷新父页面。但我希望用户输入关闭弹出窗口。

你的帮助将是非常可观的。

谢谢

4

3 回答 3

7

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...

于 2013-07-04T06:38:34.230 回答
0
<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>
于 2020-06-13T21:52:31.660 回答
0

在您的关闭按钮下,您可以添加此代码

 Response.Write("<script language=JavaScript>  opener.location.reload(); </script>")
 Response.Write("<script language='javascript'> { window.close();}</script>")
于 2016-10-20T06:46:20.717 回答