在重定向到 asp.net 中的另一个网页之前,如何在网页上显示消息框?

How can I show a message box on a web page before redirect to another web page in asp.net?

我有一个包含两个文本框和一个按钮的页面。用户填写文本框并单击按钮后,文本框的数据将写入数据库。然后应该向用户显示一个消息框,表示数据已写入数据库。当用户单击消息框上的确定按钮时,将显示另一个 asp.net 页面。我在按钮点击和页面重定向中添加了以下代码而不显示消息框。

    protected void ButtonSubmit_Click(object sender, EventArgs e)
{
    ...
    ...
    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "The data was written!" + "');", true);
    Response.Redirect("Login.aspx");
}

在 asp.net 中如何在重定向到另一个网页之前在网页上显示消息框?

您需要在警报后在客户端进行重定向:

protected void ButtonSubmit_Click(object sender, EventArgs e)
{    
    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('The data was written!'); window.location.replace('Login.aspx');", true);
}