2010-09-07 146 views
0

如何重定向頁面一旦用戶已經看到了一張確認頁?asp.net:重定向到頁面後確認?

我使用asp.net 3.5,它不顯示我的消息,而不是它只是重定向到默認頁面。我希望看到該消息,並且一旦用戶點擊「確定」,然後重定向到另一頁面。

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), key, "jAlert('" + msg + "','" + title + "');", true); 
Response.Redirect("default.aspx", false); 

回答

1

傳遞頁面重定向作爲的Javascript的一部分,而不是作爲一個服務器端重定向比:

var redirectLocation = Page.ResolveUrl("default.aspx"); 
var title = "Message Title"; 
var message = "Detail of the message"; 
var scriptTemplate = "jAlert('{0}','{1}'); location.href='{2}'"; 

var script = string.Format(scriptTemplate, message, title, redirectLocation); 
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), key, script, true); 

我打破它像有希望讓我的答案更容易閱讀,再加上它使代碼更易於維護=)

+0

它顯示的消息,但1秒後重定向到的頁面,有沒有辦法可以在那裏住到用戶採取行動(如點擊確定buttong關閉消息盒) – 2010-09-07 14:55:54

+0

@Nisar,在這種情況下,我想(快速谷歌之後)是'jAlert'是同名的jQuery http://plugins.jquery.com/project/jAlert插件。我不熟悉這個(和jQuery的網站是離線),但基於http://labs.abeautifulsite.net/projects/js/jquery/alerts/demo/有一個額外的參數,它可以傳遞給jAlert,其中您可以執行'location.href',以便在按下按鈕時觸發。 – Rob 2010-09-07 15:20:55