如何在执行循环(更新数据库)后刷新页面

how to refresh a page after i perform a looping(updating database)

在我的代码中,系统将执行循环更新数据库,在完全更新所有数据后,它将scriptalert用户,哪些数据已更新。如何在 scriptalert?

之后刷新页面

如果您知道用户将访问的页面,则可以使用 Response.Redirect() 函数。

     Response.Redirect("http://PAGEURL")

你也可以使用Javascript的location reload()

 <script type="text/javascript">
  function reloadPage()
  {
    window.location.reload()
  }
</script>

在用户控件中,您还可以在更新数据后使用 Response.Redirect:

  Response.Redirect(Request.RawUrl, true)

这也将保留您设置的变量。

您可以在显示警告信息后使用location.href=location.href;

注意: 在 ASP.Net 中,您不能在回发后立即使用 location.reload();。回发将在服务器端再次触发相同的事件,并且你将以无限循环结束

普通页面

protected void SubmitButton_Click(object sender, EventArgs e)
{
    string script = "alert('Data was updated successfully'); location.href=location.href;";

    ClientScript.RegisterStartupScript(this.GetType(), "alert" + UniqueID, script, true);
}

Ajax 页

protected void SubmitButton_Click(object sender, EventArgs e)
{
    string script = "alert('Data was updated successfully'); location.href=location.href;";

    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert" + UniqueID, script, true);
}