我試圖在重定向之前顯示警告框,但它不工作。警報框僅在 重定向未完成時才起作用。無法在重定向前打開警報框.ASP.NET
我修改了流行Alert.Show(「串」)類,從的Mads克里斯滕森如下....
public static class Alert
{
/// <summary>
/// Shows a client-side JavaScript alert in the browser.
/// </summary>
/// <param name="message">The message to appear in the alert.</param>
public static void Show(string message)
{
// Cleans the message to allow single quotation marks
string cleanMessage = message.Replace("'", "\\'");
//replacing script string with strSCript
//string script = "<script type=\"text/javascript\">alert('" + cleanMessage + "');</script>";
//added this below
string strScript = "<script type=\"text/javascript\" language=\"javascript\">";
strScript += "alert('" + cleanMessage + "');";
strScript += "window.location.href='http://localhost/Gadgeteer/IncToH/IncToH.zip';";
strScript += "</script>";
// Gets the executing web page
Page page = HttpContext.Current.CurrentHandler as Page;
// Checks if the handler is a Page and that the script isn't allready on the Page
if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
{
page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", strScript);
}
}
}
//calling from code behind
Alert.Show("message");
適合我。顯示警報後會發生重定向。 –
我沒有看到您發佈的代碼存在問題。嘗試檢查發送到瀏覽器的源以確定潛在問題。我把你的JavaScript,它工作得很好。 – kakridge