子窗口关闭时刷新父页面

时间:2011-02-21 11:26:20

标签: c# asp.net

如何在子窗口关闭时刷新父页面?

2 个答案:

答案 0 :(得分:5)

你的孩子会有这样的剧本。

<script type="text/javascript">

function refreshParent() {

//re-set the parent url to refresh
//window.opener references the parent page

  window.opener.location.href = window.opener.location.href;

}

</script>

 [...]

 // the onunload event fires when the child page is closed
<body onunload=refreshParent(); >

答案 1 :(得分:0)

尝试使用子窗口中的给定代码:

<强> ASPX:

<asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="butColSmall" 
onclick="btnCancel_Click" />

<强> ASPX.CS

protected void btnCancel_Click(object sender, EventArgs e)
    {
        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "sCancel", "window.opener.location.href = window.opener.location.href;self.close()", true);
    }