我在C#下面的代碼:C# - 頁面重定向不能正常工作
if (function.Equals("Larger50"))
{
Request req = new Request();
string result = req.doRequest("function=" + function + "&num=" + number, "http://localhost:4000/Handler.ashx");
if (result.Equals("True") || result.Equals("true"))
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), null, "window.open('http://localhost:4000/Larger.aspx?num=" + number + "', '_newtab')", true);
}
if(result.Equals("False") || result.Equals("false"))
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), null, "window.open('http://localhost:4000/Smaller.aspx', '_newtab')", true);
}
if(result.Equals("Error") || result.Equals("error"))
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), null, "window.open('http://localhost:4000/ErrorPage.htm', '_newtab')", true);
}
Session["result"] = result;
Page.ClientScript.RegisterStartupScript(Page.GetType(), null, "window.location.href = 'Results.aspx'", true);
}
結果變量可以有以下三種中的任何值(如果服務器響應):
我)真的 ii)錯誤 iii)錯誤
此代碼的主要問題在於三個if語句中的每一箇中的新選項卡腳本正常工作。但是,打開Results.aspx頁面的最後一個腳本由於某種原因沒有執行。如果所有其他代碼都被註釋掉,那麼腳本編寫得非常完美。我應該如何解決這個問題?
我試着用Response.Redirect(「Results.aspx」)替換它,然後這個exeuctes和所有其他三個腳本永遠不會執行。
將完整的網址添加到Results.aspx – saj
Results.aspx是我工作的當前項目中的一個頁面。所有其他URL都是到服務器機器上的。 – Matthew
這些腳本完全可以自行完成,但是當它們組合在一起時,它們不能以某種原因或另一種方式工作。這就像第一個遇到的腳本執行一樣,並且下一個腳本被忽略。 – Matthew