【问题标题】:How to close a pop up window and return control to parent page on successs如何在成功时关闭弹出窗口并将控制权返回到父页面
【发布时间】:2010-09-03 10:00:10
【问题描述】:

我正在使用此代码。当我单击主页上的按钮时会弹出此弹出窗口。现在我希望在成功更改密码并重新加载主页时关闭弹出窗口,但如果密码未更改,然后再次刷新弹出窗口。 这是代码.....

<asp:Textbox id="curnt_paswrd" textmode="Password" runat="server" size="30" />
<asp:Textbox id="new_paswrd" textmode="Password" runat="server" size="30" />

【问题讨论】:

  • 这个弹出窗口,仅仅是你使用window.open()打开的一个新的浏览器窗口吗?

标签: javascript asp.net ajax popup


【解决方案1】:

给你....

这是用来打开弹窗的......

<html> 
<head>
    <script type="text/javascript">
      var passwordPopup;

      function popUpPassword()
      {
        passwordPopup = window.open("ChangePassword.aspx");

        window.onbeforeunload = function()
        {
          alert("yay I reloaded!");
          window.onbeforeunload = null;
        }
      }
    </script>
</head>
<body>
   <button onclick="popUpPassword();">Popup Password Change</button>
</body>
</html>

这用于重新加载主页并关闭弹出窗口......

public partial class ChangePassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

  protected void SubmitPassword_Click(object sender, EventArgs e)
    {
      bool passwordChanged = true;

      if (passwordChanged)
      {

        // Get a ClientScriptManager reference from the Page class.
        ClientScriptManager cs = Page.ClientScript;

        // Check to see if the client script is already registered.
        if (!cs.IsClientScriptBlockRegistered(this.GetType(), "popUpPwScript"))
        {
          StringBuilder jscript = new StringBuilder();
          jscript.Append("<script type=\"text/javascript\">");
          jscript.Append("window.opener.location.reload(); window.close();");
          jscript.Append("</script>");
          cs.RegisterClientScriptBlock(this.GetType(), "popUpPwScript", jscript.ToString(), false);
        }
      }
      else
      {
        //do something else
      }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-03
    • 2011-07-31
    • 1970-01-01
    • 2016-12-19
    • 1970-01-01
    • 2013-09-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多