Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.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
C# ASP.NET中重定向前的Javascript警报_C#_Javascript_Asp.net_Ajax_Updatepanel - Fatal编程技术网

C# ASP.NET中重定向前的Javascript警报

C# ASP.NET中重定向前的Javascript警报,c#,javascript,asp.net,ajax,updatepanel,C#,Javascript,Asp.net,Ajax,Updatepanel,我使用以下代码在更新面板中更新时显示消息 string jv = "alert('Time OutAlert');"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", jv, true); 它很好用 但是,当我使用重定向后,它加载页面而不显示消息。我希望用户看到的消息,并在点击“确定”后,它应该重定向 string jv = "alert('Time OutAlert');"; ScriptManager

我使用以下代码在更新面板中更新时显示消息

string jv = "alert('Time OutAlert');";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", jv, true);
它很好用

但是,当我使用重定向后,它加载页面而不显示消息。我希望用户看到的消息,并在点击“确定”后,它应该重定向

string jv = "alert('Time OutAlert');";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", jv, true);
Response.Redirect("~/Nextpage.aspx");

您不能这样做,因为消息是在客户端运行的,所以您尝试这样做,但是在加载页面以显示消息之前,您对代码进行了重定向

方法是在消息发出后立即调用客户端重定向,如下所示:

window.location = "NextPage.asps";

使用javascript显示警报,然后使用相同的脚本执行重定向:

ScriptManager.RegisterStartupScript(this,this.GetType(),"redirect",
"alert('Time OutAlert'); window.location='" + 
Request.ApplicationPath + "Nextpage.aspx';",true);
这个很好用
如何将其添加到内置函数中?当使用路由名称而不是整页名称时,此解决方案也有效。
                string message = "Upadate Successfull !!";
                string url = "/Post.aspx";
                string script = "{ alert('";
                script += message;
                script += "');";
                script += "window.location = '";
                script += url;
                script += "'; }";
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "alert", script, true);