[英]Javascript Alert before redirecting in ASP.NET
我正在使用以下代碼在更新面板中更新時顯示消息
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");
使用 javascript 顯示警報,然后使用相同的方法進行重定向:
ScriptManager.RegisterStartupScript(this,this.GetType(),"redirect",
"alert('Time OutAlert'); window.location='" +
Request.ApplicationPath + "Nextpage.aspx';",true);
你不能這樣做,你嘗試的方式是因為消息在客戶端運行,但是你在頁面加載之前對后面的代碼進行重定向以顯示消息。
這樣做的方法是在消息之后立即調用客戶端重定向為:
window.location = "NextPage.asps";
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.