【问题标题】:How can i re-load parent page when popup page is closed弹出页面关闭时如何重新加载父页面
【发布时间】:2014-11-03 12:46:08
【问题描述】:
public static string PopUpParentPage
{
    get
    {
        if (HttpContext.Current.Session["PopUpParentPage"] == null)
        {
           return (string.Empty);
        }
        else
        {
            return (string)(HttpContext.Current.Session["PopUpParentPage"]);
        }
    }
    set
    {
        HttpContext.Current.Session["PopUpParentPage"] = value;
    }
}

上面的代码可以让我成为弹出窗口的父级。

下面是我如何从父窗口中的链接按钮单击事件打开弹出窗口

protected void lnkOpenPopUp_Click(object sender, ImageClickEventArgs e)
 {
    string strScript = "<script>fnChangeLocationPopup();</script>";
    this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "openPopup", strScript);
}

这也是我通过单击弹出页面上的按钮关闭弹出窗口的方式

protected void btnClosePopUp_Click(object sender, ImageClickEventArgs e)
  {
    string strScript = "<script>fnChangeLocationPopup();</script>";
    this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "closePopup", strScript);
}

现在我想要重新加载父页面,以便刷新数据。如果我知道在上面的第一个代码 sn-p 中检索的父页面 URL 的值,一旦弹出表单关闭,如何在 btnClosePopUp_Click 上刷新它?

【问题讨论】:

    标签: javascript c# asp.net


    【解决方案1】:

    Javascript:在你的函数fnChangeLocationPopup()下面写代码

     window.location.reload();
    

    代码隐藏:

    Response.Redirect(Request.RawUrl);
    

    这将重定向到同一页面。

    【讨论】:

      【解决方案2】:

      您可以使用以下代码获取弹出页面的Close 事件。 并编写代码,使用.parent 属性重新加载父窗口,如下所示。

      <script type="text/javascript">
              window.onbeforeunload = closePopup;
      function closePopup(){
      window.parent.location.reload();
      }
      </script>
      

      只需将上面的代码放在&lt;head&gt;标签中的弹出页面中即可。

      【讨论】:

        【解决方案3】:

        试试这个javascript

        function myfunction() {
                if (window.opener != null) {
                    opener.location.reload(true);
                    window.close();
                }
            }
        

        【讨论】:

          猜你喜欢
          • 2013-09-15
          • 2012-07-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多