Sys.WebForms.PageRequestManagerServerErrorException: 抛出 'System.Web.HttpUnhandledException' 类型的异常

Sys.WebForms.PageRequestManagerServerErrorException: Exception of type 'System.Web.HttpUnhandledException' was thrown

目前我正在(在 Windows 上)开发一个 asp 页面,用于提取用户提交的主题评分,并为管理员显示信息。 window 显示每个主题的平均评分,如果用户决定,应该能够单击一个按钮("Details" 按钮)让页面显示每个单独提交的模式。发生的事情是,当单击 "Details" 按钮时,Google Chrome 的控制台中会弹出以下内容:

Uncaught Error: Sys.WebForms.PageRequestManagerServerErrorException: 
Exception of type 'System.Web.HttpUnhandledException' was thrown.
    at Function.Error.create (ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_AifO125gmd63G1Swcz7qV9r0jEeTlD3He6XxAk%2bAR8o%3df_f&t=636832247730000000&n=f:5)
    at Sys.WebForms.PageRequestManager._createPageRequestManagerServerError (ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_ZPalWLzUD8kN%2f8CMQnRLOXpq%2bJ1Q98VkxisU6TES%2fxc%3df_f&t=636832247730000000&n=f:5)
    at Sys.WebForms.PageRequestManager._onFormSubmitCompleted (ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_ZPalWLzUD8kN%2f8CMQnRLOXpq%2bJ1Q98VkxisU6TES%2fxc%3df_f&t=636832247730000000&n=f:5)
    at Array.<anonymous> (ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_AifO125gmd63G1Swcz7qV9r0jEeTlD3He6XxAk%2bAR8o%3df_f&t=636832247730000000&n=f:5)
    at ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_AifO125gmd63G1Swcz7qV9r0jEeTlD3He6XxAk%2bAR8o%3df_f&t=636832247730000000&n=f:5
    at Sys.Net.WebRequest.completed (ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_AifO125gmd63G1Swcz7qV9r0jEeTlD3He6XxAk%2bAR8o%3df_f&t=636832247730000000&n=f:5)
    at XMLHttpRequest._onReadyStateChange (ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_AifO125gmd63G1Swcz7qV9r0jEeTlD3He6XxAk%2bAR8o%3df_f&t=636832247730000000&n=f:5)
Error.create @ ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_AifO125gmd63G1Swcz7qV9r0jEeTlD3He6XxAk%2bAR8o%3df_f&t=636832247730000000&n=f:5
_createPageRequestManagerServerError @ ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_ZPalWLzUD8kN%2f8CMQnRLOXpq%2bJ1Q98VkxisU6TES%2fxc%3df_f&t=636832247730000000&n=f:5
_onFormSubmitCompleted @ ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_ZPalWLzUD8kN%2f8CMQnRLOXpq%2bJ1Q98VkxisU6TES%2fxc%3df_f&t=636832247730000000&n=f:5
(anonymous) @ ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_AifO125gmd63G1Swcz7qV9r0jEeTlD3He6XxAk%2bAR8o%3df_f&t=636832247730000000&n=f:5
(anonymous) @ ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_AifO125gmd63G1Swcz7qV9r0jEeTlD3He6XxAk%2bAR8o%3df_f&t=636832247730000000&n=f:5
completed @ ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_AifO125gmd63G1Swcz7qV9r0jEeTlD3He6XxAk%2bAR8o%3df_f&t=636832247730000000&n=f:5
_onReadyStateChange @ ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_AifO125gmd63G1Swcz7qV9r0jEeTlD3He6XxAk%2bAR8o%3df_f&t=636832247730000000&n=f:5
XMLHttpRequest.send (async)
executeRequest @ ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_AifO125gmd63G1Swcz7qV9r0jEeTlD3He6XxAk%2bAR8o%3df_f&t=636832247730000000&n=f:5
executeRequest @ ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_AifO125gmd63G1Swcz7qV9r0jEeTlD3He6XxAk%2bAR8o%3df_f&t=636832247730000000&n=f:5
invoke @ ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_AifO125gmd63G1Swcz7qV9r0jEeTlD3He6XxAk%2bAR8o%3df_f&t=636832247730000000&n=f:5
_onFormSubmit @ ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_ZPalWLzUD8kN%2f8CMQnRLOXpq%2bJ1Q98VkxisU6TES%2fxc%3df_f&t=636832247730000000&n=f:5
(anonymous) @ ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_AifO125gmd63G1Swcz7qV9r0jEeTlD3He6XxAk%2bAR8o%3df_f&t=636832247730000000&n=f:5
b @ ScriptResource.axd?d=%2fS7cVnwlWD4SmD%2b83Da0flhLDlvn%2b4mQMwbS6JaJMJ8%3d_AifO125gmd63G1Swcz7qV9r0jEeTlD3He6XxAk%2bAR8o%3df_f&t=636832247730000000&n=f:5

我以前从未见过这个,老实说我不确定为什么会出现。只有当页面托管在使用 Apache/Mod_Mono 的 Ubuntu 系统上时单击按钮时才会发生这种情况。我还没有找到任何原因,说明为什么会出现这种情况。以下是我的代码,前后端:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
   <asp:UpdatePanel ID="FeedbackViewContent" runat="server">
      <ContentTemplate>
         <div class="modal fade" id="RatingsModalCenter" tabindex="-1" role="dialog" aria-labelledby="RatingsModalCenterTitle" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
               <div class="modal-content">
                  <div class="modal-header">
                     <h4 class="modal-title" id="RatingsModalCenterTitle" runat="server">Application Feedback</h4>
                     <button type="button" id="close" class="close close-dark" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                     </button>
                  </div>
                  <div class="modal-body" runat="server" id="EditorModalBody">
                     <div class="row">
                        <div class="col-6 col-lg-6">
                           <h6>Information Average (All Time):</h6>
                           <asp:TextBox ID="txtRateInfo" runat="server" ReadOnly="true" CssClass="kv-fa rating-loading"></asp:TextBox>
                           <asp:Label ID="lblRateInfo" runat="server" Text="" AssociatedControlID="txtRateInfo"></asp:Label>
                        </div>
                        <div class="col-6 col-lg-6">
                           <h6>Presentation Average (All Time):</h6>>
                           <asp:TextBox ID="txtRatePres" runat="server" ReadOnly="true" CssClass="kv-fa rating-loading"></asp:TextBox>
                           <asp:Label ID="lblRatePres" runat="server" Text="" AssociatedControlID="txtRatePres"></asp:Label>
                        </div>
                     </div>
                  </div>
               <div class="modal-footer">
                  <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
               </div>
            </div>
         </div>
      </div>
      <asp:Panel ID="PanelContent" runat="server"></asp:Panel>
   </ContentTemplate>
</asp:UpdatePanel>
<script type="text/javascript">
   $('.kv-fa').rating({
      theme: 'krajee-fa',
      min: '1',
      max: '5',
      size: 'xs',
      step: '0.1',
      stars: '5',
      displayOnly: true,
      filledStar: '<i class="fa fa-star"></i>',
      emptyStar: '<i class="fa fa-star-o"></i>',
      showCaption: false,
      showClear: true,
   });

   function showModal() {
      $("#RatingsModalCenter").modal('toggle');
   }
</script>

在代码隐藏中:

//This method is called in Page_Load()
//Purpose is to add the categories to the page that were rated.
protected void ViewReportLayout() {
   PanelContent.Controls.Clear();
   DataTable tblRatingResults = ratings.Select("[Select query to get topics & avg rating from table]");
      if (tblRatingResults.Rows.Count > 1) {
         var listUnordered = new HtmlGenericControl("ul");
         PanelContent.Controls.Add(listUnordered);
//for each topic entry in the results
         foreach (DataRow rating in tblRatingResults.Rows) {
            HtmlGenericControl ListCatItem = new HtmlGenericControl("li");
            ListCatItem.Attributes.Add("class", "list-group-item p-2");
            if (rating["overallAvg"] != null && rating["overallAvg"].ToString() != "") {
//Is there a rating for this topic?
               HtmlGenericControl rateCol1 = new HtmlGenericControl("div");
               HtmlGenericControl rateCol2 = new HtmlGenericControl("div");
               TextBox rateStar = new TextBox();
               HtmlGenericControl rateStr = new HtmlGenericControl("span");
               rateStar.Attributes.Add("class", "kv-fa");
               rateStar.Text = rating["overallAvg"].ToString();
               rateStr.InnerText = Math.Round((decimal)rating["overallAvg"],2).ToString() + " / 5";
               CatRow2.Controls.Add(rateCol1);
               CatRow2.Controls.Add(rateCol2);
               ListCatItem.Controls.Add(rateStar);
               ListCatItem.Controls.Add(rateStr);
            } else {
               HtmlGenericControl rateCol1 = new HtmlGenericControl("div");
               var rateStar = new HtmlGenericControl("span");
               rateCol1.Attributes.Add("class", "col-12 py-0 mb-0");
               rateStar.InnerText = "NO DATA";
               rateCol1.Controls.Add(rateStar);
               ListCatItem.Controls.Add(rateCol1);
            }
//Finally, add the button to show the "Details" modal.
            Button rateBtnDetail = new Button();
            rateBtnDetail.ID = "btnDetail-" + rating["CatID"].ToString();
            rateBtnDetail.Text = "View Details";
            rateBtnDetail.Click += rateBtnDetail_Click;
            CatRow3.Controls.Add(rateBtnDetail);
            listUnordered.Controls.Add(ListCatItem);
         }
      }
   }
}
//This method is called when a 'rateBtnDetail' is clicked.
void rateBtnDetail_Click(object sender, EventArgs e) {
   Button btnClicked = (Button)sender;
   string btnName = btnClicked.ID;
   int catID;
   if (int.TryParse(btnName.Replace("btnDetail-", ""), out catID) != false) {
      string saniCatID = training.Quote(catID.ToString());
      string catAvgBothQuery = "SELECT AVG(ratings.RateInformation) AS 'AvgInfo', AVG(ratings.RatePresentation) AS 'AvgPres', ratings.CatID, categories.CatName FROM categories LEFT JOIN ratings ON categories.CatID = ratings.CatID WHERE ratings.CatID = " + saniCatID + " GROUP BY ratings.CatID";
      string catRateDetailQuery = "SELECT * FROM ratings WHERE CatID = " + saniCatID + " ORDER BY RateTimestamp DESC LIMIT 20";
       DataTable CatAvgBoth = training.Select(catAvgBothQuery);
       DataTable CatRateDetail = training.Select(catRateDetailQuery);
       if (CatAvgBoth.Rows.Count == 1 && CatRateDetail.Rows.Count > 0) {
       txtRateInfo.Text = CatAvgBoth.Rows[0]["AvgInfo"].ToString();
       lblRateInfo.Text = Math.Round((decimal)CatAvgBoth.Rows[0]["AvgInfo"], 2).ToString() + " / 5";
       txtRatePres.Text = CatAvgBoth.Rows[0]["AvgPres"].ToString();
       lblRatePres.Text = Math.Round((decimal)CatAvgBoth.Rows[0]["AvgPres"], 2).ToString() + " / 5";
       }
    }
    ScriptManager.RegisterStartupScript(FeedbackViewContent, FeedbackViewContent.GetType(), "popModal", "showModal();", true);
}

基本上,点击任何主题的 rateBtnDetail 按钮后,上述错误会出现在 Chrome 的控制台中。我已经注释掉了我调用 "showModal();" 启动脚本的 ScriptManager 行,当单击任何“详细信息”按钮时它仍然会生成错误。此时,我迷路了,正在寻找一些方向这可能是由什么引起的。

解决了,原来是一个简单的错误。我的问题是,对于我的 rateStar 文本框,我试图使用 rateStar.Attributes.Add("class", "kv-fa"); 添加 css class 作为属性。

相反,我需要使用 rateStar.CssClass = "kv-fa";