在ASP.NET中重定向之前的Javascript警报

问题描述 投票:11回答:4

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

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");
c# javascript asp.net ajax updatepanel
4个回答
28
投票

使用javascript显示警报,然后使用相同的方法进行重定向:

ScriptManager.RegisterStartupScript(this,this.GetType(),"redirect",
"alert('Time OutAlert'); window.location='" + 
Request.ApplicationPath + "Nextpage.aspx';",true);

3
投票

您无法执行此操作,因为该消息正在客户端运行,但是您在加载页面以显示该消息之前在代码后面进行了重定向。

方法是在客户端重定向为以下消息后立即调用:

window.location = "NextPage.asps";

0
投票

此方法很好

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

0
投票

非常感谢你的作品。.>

© www.soinside.com 2019 - 2024. All rights reserved.