2011-10-21 76 views
1

在按鈕上單擊我在JS函數中調用javascript函數我重定向到aspx頁面並在aspx頁面中我想重定向到另一頁面(此部分不管用)。 response.redirect不重新定向,只是發回當前頁面。任何想法爲什麼它不工作。Response.Redirect()不起作用.net 4.0

這裏是我的代碼:

Review.aspx:

<asp:Button ID="btnComplt" runat="server" Text="Complete" OnClientClick ="return compAsgn()" /> 

function compAsgn() { 
     if (window.confirm("Submit all images and complete the assignment?")) 
      window.location = "SendImages.aspx?insid=" + $("#IAssignmentId").val() + '&option=complete'; 
     else 
      return false; 

SendImages.aspx:

protected void Page_Load(object sender, EventArgs e) 
     { 
      assignmentId = Convert.ToInt32(Request.QueryString["insid"]); 
      string url = "Review.aspx?insid" + assignmentId.ToString() + "&viewOption=review"; 

      string qstrVal = string.Empty; 
      qstrVal = Request.QueryString["option"].ToString().ToLower(); 
      if (qstrVal != null && qstrVal == "complete") 
      { 
       using (ServiceClient client = new Proxies.ServiceRef.ServiceClient()) 
       { 
        List<AssignmentInfo> ainfo = new List<AssignmentInfo>(); 
        ainfo = client.GetAssignmentInfo(assignmentId); 
        if (ainfo.Count > 0) 
        { 
         if (ainfo[0].UploadedCount == 0) 
         { 
// AfarSessionData class has a property called ProfileId, which is session variable. 
          if (AfarSessionData.ProfileId == "000000") 
           url = "Admin.aspx"; 
          else 
           url = "HomePage.aspx"; 
         } 


        } 
       } 

      } 


      Response.Redirect(url, false); 
     } 

注:當我調試我看到控制擊球發送圖片頁面,但我看到response.redirect不重新定向,只是發回當前頁面。

+0

使用Fiddler,看到標題說什麼。你應該有一個302 http狀態。 –

+0

當它到達代碼中的那一點時,url的價值是什麼? – NotMe

+0

Admin.aspx是URL的值 – BumbleBee

回答

2

據我所知,你沒有做任何事情來結束請求。我不是一個ASP.NET的傢伙,但我認爲要麼:

  • 使第二個參數true有效「硬中止」與異常
  • 請求讓第二個參數false,但隨後調用CompleteRequest停止管道
+0

或第三個選項,組織您的代碼,以便重定向是代碼路徑中的最後一件事。 – x0n

+1

這是代碼中的最後一件事。 – BumbleBee

+0

@Jon謝謝。可以告訴我如何使用EndRequest。 – BumbleBee

1

一些額外的信息與約翰長柄水杓答案的其餘部分:

//ends request, no exception, calls Response.End() internally 
Response.Redirect (url, true); 

try 
{ 
    Response.Redirect (url, false); 
} 
catch(ThreadAbortException e) 
{ 
    //do whatever you need to 
} 

下面是對這個問題的一些信息:

PRB: ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer

+0

我不確定你可以從已中止的線程中捕獲ThreadAbortException? – rossisdead

+1

請參閱鏈接,「您可以使用try-catch語句來捕獲此異常。」 –

+0

呵呵,那怎麼樣。今天我學到了! – rossisdead

相關問題