2012-07-03 122 views
1

我有一個導致「Internet Explorer無法顯示網頁」錯誤的代碼塊。當我單擊提交按鈕時,如果選中無單選按鈕,網頁狀態欄將顯示「等待主機響應」,然後顯示「Internet Explorer無法顯示網頁」。當我瀏覽visual studio中的代碼時,代碼執行得很好,並且沒有任何catch塊被執行。在asp.net中出現錯誤「Internet Explorer無法顯示網頁」

enter image description here

我怎樣才能捕獲錯誤,並找出原因正在顯示錯誤頁面?

protected void btnSubmit_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      if (rbtnSearchBy1.Checked) 
      { 
       Server.Transfer("ViewEmpHistory.aspx"); 
      } 
      if (rbtnSearchBy2.Checked) 
      { 
       Server.Transfer("SearchEmp.aspx"); 
      } 
      if (rbtnSearchBy3.Checked) 
      { 
       Server.Transfer("ViewEmpCard.aspx"); 
      } 
     } 

     catch (ThreadAbortException) 
     { 
      throw; 
     } 
     catch (Exception ex) 
     { 
      Response.Write(ex.ToString()); 
     } 
    } 
+1

沒有選中複選框,您對行爲有什麼期待?您的邏輯不會針對該情況調用Transfer。 – Sean

+0

我期待它不會去「」Internet Explorer無法顯示網頁「錯誤.... – DotNetRookie

+0

但你發送的請求,然後響應服務你沒有反應。也許你應該考慮添加類似的東西{服務器.Transfer(「StandardErrorPage.aspx」)} – Sean

回答

1

無論.cs頁面中您的「btnSubmit_Click」處於打開狀態,請在處指出一個斷點即 page_load事件。
此外,在「ViewEmpHistory.aspx」,「SearchEmp.aspx」&「ViewEmpCard.aspx」的page_load事件上放置一個斷點。 (所以現在你有四個斷點)。

通過該項目再次步驟,並確保正在傳遞的所有參數值正確,還要確保你有正確的邏輯(如適用)If (!PostbacK)條件等

HTH

1

如果你不選擇一個單選按鈕,這是正常的,你不輸入你的catch,因爲你的應用程序沒有拋出異常。 但您可以查看事件日誌

輸入您的CMD:EVENTVWR訪問您的事件日誌

enter image description here

+0

事件查看器沒有相關信息(查看時間戳時) – DotNetRookie

+0

在global.asax中添加beakpoint - Application_Start –

1

調試這些類型的問題,我經常發現它更容易使用跟蹤。

您可以打開追蹤application levelpage level。然後

你的方法調用將變爲:

protected void btnSubmit_Click(object sender, EventArgs e) 
{ 
    try 
    { 
     if (rbtnSearchBy1.Checked) 
     { 
      Server.Transfer("ViewEmpHistory.aspx"); 
     } 
     if (rbtnSearchBy2.Checked) 
     { 
      Server.Transfer("SearchEmp.aspx"); 
     } 
     if (rbtnSearchBy3.Checked) 
     { 
      Server.Transfer("ViewEmpCard.aspx"); 
     } 
    } 
    catch(Exception ex) 
    { 
     Trace.Warn("Exception Caught", "Exception: btnSubmit_Click", ex); 
    } 
} 

你可以看一下跟蹤日誌由然後導航至Trace Viewer

0

你已經什麼完成的結構不完整。如果塊是獨佔的,它會更乾淨 - 這就是爲什麼我將else語句添加到下面的代碼中。我還指出了你想要處理的地方,在評論中沒有選中按鈕。

但是你是對的,沒有任何異常被拋出。你的代碼沒有拋出一個,當你結束處理請求而沒有返回任何類型的響應時,它不會引發異常。

 if (rbtnSearchBy1.Checked) 
     { 
      Server.Transfer("ViewEmpHistory.aspx"); 
     } 
     else if (rbtnSearchBy2.Checked) 
     { 
      Server.Transfer("SearchEmp.aspx"); 
     } 
     else if (rbtnSearchBy3.Checked) 
     { 
      Server.Transfer("ViewEmpCard.aspx"); 
     } 
     else 
     { 
      // Here's where the logic will flow to if no radio button is clicked. 
      // We could 
      // * Server.Transfer to a default location 
      // * Throw an exception 
      // * Do nothing, which returns no response, and causes 
      // IE to complain that it could not display the webpage. 
     } 
相關問題