Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何发送警报并刷新页面?_Asp.net - Fatal编程技术网

Asp.net 如何发送警报并刷新页面?

Asp.net 如何发送警报并刷新页面?,asp.net,Asp.net,我一直在阅读StackOverFlow中的一些主题,我找到了一些刷新页面的方法,如: Response.Redirect(Request.RawURL);,响应.重定向(绝对.Uri)等… 但我需要发送一个确认警报,并刷新页面。。。现在,我正在使用此方法发送警报: ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('Well Done !');", true); 但是使用这些方法中的任何一种刷新页

我一直在阅读
StackOverFlow
中的一些主题,我找到了一些刷新页面的方法,如:
Response.Redirect(Request.RawURL);,响应.重定向(绝对.Uri)等…

但我需要发送一个确认警报,并刷新页面。。。现在,我正在使用此方法发送警报:

ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('Well Done !');", true);  
但是使用这些方法中的任何一种刷新页面,都不会触发警报。因此,我需要知道一种很好的方法来实现这一点。

因为我有一些
DropDownList
数据库中的数据,我正在对数据进行一些
编辑
,所以当用户点击按钮编辑当前数据时,它会显示一条消息,如
编辑成功
,然后用新数据刷新页面。

客户端重定向如何

alert("You're now will be redirected");
window.location.reload();

由于alert()是同步函数,因此只有当用户单击“确定”时才会触发重定向。

上述客户端脚本可以通过这种方式添加到代码隐藏中

protected void Render()
{
    System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder("<script "
        + "type='text/javascript'>"
        );
    stringBuilder.Append("alert('hi');");
    stringBuilder.Append("window.location.reload();");
    stringBuilder.Append("</script>");

}
protectedvoid Render()
{
System.Text.StringBuilder StringBuilder=新建System.Text.StringBuilder(“”)
);
追加(“警报('hi');”);
追加(“window.location.reload();”;
stringBuilder.Append(“”);
}

要刷新,可以使用document.location.reload(true)@ShariqueAnsari那警报呢?也将被解雇?您可以使用此警报(“干得好!”);文档。位置。重新加载(true)@ShariqueAnsari您的
文档.location.reload(true)
窗口.location.reload有何不同?为什么
参数为true
?感谢您将布尔值true添加到重新加载窗口。location.reload(true)它将从服务器加载。我从未使用过此选项。我在哪里使用这些代码?我希望在客户端单击按钮
edit
时触发所有这些。但不是在用户按下按钮的时候。我希望在成功完成所有方法后触发警报/刷新。我想通过ScriptManager注册此脚本,就像您的问题一样。您的示例没有调用alert(),因为在执行任何脚本之前页面会重新加载。OMG,工作!!Thanks男士:D使用这种方法有什么不好的地方吗?或者这是一个好的做法?