我正在使用此代码。当我点击主页面上的按钮时会弹出这个弹出窗口。现在我想要在成功更改密码并重新加载主页面时关闭弹出窗口,但是如果密码未更改,然后再次刷新弹出窗口。 这是代码.....
<asp:Textbox id="curnt_paswrd" textmode="Password" runat="server" size="30" />
<asp:Textbox id="new_paswrd" textmode="Password" runat="server" size="30" />
答案 0 :(得分:0)
这里你去......
这是打开弹出窗口....
<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
}
}
}