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