如何在显示消息框后关闭当前的webform

时间:2015-03-11 10:43:37

标签: c# asp.net webforms

我使用下面的代码打开一个消息框:

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

        }

如何在单击此消息框的“确定”按钮后关闭当前页面?

3 个答案:

答案 0 :(得分:0)

在网络表单中,您无法关闭页面,您需要做的是将页面重定向到其他页面,如果您在警报后添加重定向,则应在警报关闭时进行重定向

如果您不知道如何重定向页面,那么这可能有所帮助 aspx page to redirect to a new page 然而,网格形式是我还在学习的东西

答案 1 :(得分:0)

使用window.open()以弹出方式打开当前页面,然后在页面中编写Javascript函数,例如

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

然后将服务器端代码更改为

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

答案 2 :(得分:0)

尝试一下

string message =“警报(“您的批准已成功保存”); self.close();”; ScriptManager.RegisterClientScriptBlock((发送方为控件),this.GetType(),“ alert”,message,true);