【问题标题】:Sys.WebForms.PageRequestManagerServerErrorException: Exception of type 'System.Web.HttpUnhandledException' was thrownSys.WebForms.PageRequestManagerServerErrorException:引发了“System.Web.HttpUnhandledException”类型的异常
【发布时间】:2019-01-25 19:48:54
【问题描述】:

目前我正在开发(在 Windows 上)一个 asp 页面,该页面可以提取用户提交的主题评分,并为管理员显示信息。该窗口显示每个主题的平均评分,如果用户决定,应该能够单击一个按钮(“详细信息”按钮)以使页面显示每个单独提交的模式。发生的情况是,当单击“详细信息”按钮时,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 行启动脚本,当单击任何“详细信息”按钮时,它仍然会产生错误。此时,我迷路了,正在寻找可能导致这种情况的方向。

【问题讨论】:

    标签: c# asp.net asp.net-ajax .net-4.5


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2013-01-14
      • 2013-08-28
      • 2015-07-18
      • 2011-02-14
      • 1970-01-01
      相关资源
      最近更新 更多