簡體   English   中英

顯示消息框后如何關閉當前Web表單

[英]how to close current webform after display messagebox

我使用下面的代碼打開一個消息框:

protected void btnUpdate_Click(object sender, EventArgs e)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Messagebox", "alert('Record Updated successfully.Note: This tab is now getting close');", true);

        }

單擊此消息框的“確定”按鈕后如何關閉當前頁面?

在Web表單中,您無法關閉頁面,您要做的就是將頁面重定向到另一個頁面,如果在警報后添加重定向,則應該在警報關閉時發生

如果您不知道如何重定向頁面,則這可能有助於aspx頁面重定向到新頁面,但是Webforms是我仍在學習的內容

使用window.open()打開當前頁面作為彈出窗口,然后在該頁面中編寫Javascript函數,例如

<script>
function confirmAndClose()
{
    var conf = confirm("Confirm to close");
    if (conf == true) {
          window.close();
                      } 
}
</script>

然后將您的服務器端代碼更改為

ScriptManager.RegisterClientScriptBlock(this, "script","confirmAndClose()");

嘗試這個,

字符串消息=“警報('您的批准已成功保存'); self.close();“; ScriptManager.RegisterClientScriptBlock((發送方為控件),this.GetType(),“ alert”,message,true);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM