javascript子页面刷新父页面

来源:互联网 发布:汉字拉丁化 知乎 编辑:程序博客网 时间:2024/06/04 20:15

前台页面为 子页面为一个按钮:

<form id="form1" runat="server">
    <div>
        <asp:Button runat="server" ID="Bt_Add" Text="添加" Width="80px" Height="20px" OnClick="Bt_Add_Click" />
    </div>
 </form>

在后台onClick中添加:

 protected void Bt_Add_Click(object sender, EventArgs e)

{

      //你要做的事情然后刷新父页面

      //刷新父页面

      ClientScript.RegisterStartupScript(this.GetType(), "ReLoad", "ReLoad();", true);

}

在子页面加入javascript脚本

<script type="text/javascript" language="javascript">

function ReLoad() {
            if(window.opener)
            {//如果父页面还在的话
                window.opener.location.reload();//先刷新父页面
                window.opener = null;//
                window.close();//这两句是为了不出现提示
            }
        }

</script>

点击时会摔新父页面。在关闭本页面!