当前,我正在(在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">×</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的控制台中。我已经注释掉ScriptManager行,在其中我将其称为“ showModal();”。启动脚本,当单击任何“详细信息”按钮时,它仍然会产生错误。这时,我迷路了,正在寻找可能的原因。
答案 0 :(得分:0)
解决了这个问题,原来是一个简单的错误。我的问题是,对于我的connection_traits
TextBox,我试图使用rateStar
将css类添加为属性。
相反,我需要使用rateStar.Attributes.Add("class", "kv-fa");
。