简体   繁体   English

显示消息框后如何关闭当前Web表单

[英]how to close current webform after display messagebox

I use the code below to open a message box: 我使用下面的代码打开一个消息框:

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);

        }

How to close the current page after a click on the OK button of this message box? 单击此消息框的“确定”按钮后如何关闭当前页面?

in web forms you can't close the page, what you will have to do is redirect the page to a different page, and if you add the redirect after the alert it should happen when the alert closes 在Web表单中,您无法关闭页面,您要做的就是将页面重定向到另一个页面,如果在警报后添加重定向,则应该在警报关闭时发生

if you don't know how to redirect a page then this may help aspx page to redirect to a new page however webforms is something i'm still learning myself 如果您不知道如何重定向页面,则这可能有助于aspx页面重定向到新页面,但是Webforms是我仍在学习的内容

Open the current page as popup using window.open() then write a Javascript function in the page such as 使用window.open()打开当前页面作为弹出窗口,然后在该页面中编写Javascript函数,例如

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

then change you server side code to 然后将您的服务器端代码更改为

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

Try this, 尝试这个,

string message = "alert('Your Approval Has Been Saved Success');self.close();"; 字符串消息=“警报('您的批准已成功保存'); self.close();“; ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", message, true); ScriptManager.RegisterClientScriptBlock((发送方为控件),this.GetType(),“ alert”,message,true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM