2010-09-03 73 views
2

我正在使用此代碼。當我單擊主頁上的一個按鈕時彈出窗口彈出。現在我想彈出窗口關閉如果密碼成功更改並重新加載主頁面,但如果密碼未更改,則再次刷新彈出窗口。 下面是代碼.....如何關閉彈出窗口並將成功返回到父頁面

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

+0

這個彈出窗口,它只是一個使用window.open()打開的新瀏覽器窗口嗎? – CyberDude 2010-09-03 10:29:14

+0

我的回答有幫助嗎? – hyprsleepy 2010-09-15 17:53:50

回答

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 
     } 
    } 
} 
相關問題