我有一個主頁,它具有加載不同內容的用戶控件的各種佔位符。標題將是一個,主頁面內容是另一個。在主內容用戶控件內,它根據需要顯示的頁面加載各種其他用戶控件。UpdatePanel僅在初始部分回傳時更新
母版頁
<%@ Master Language="C#" AutoEventWireup="true" EnableViewState="true" CodeBehind="Admin.Master.cs" Inherits="SitefinityWebApp.Admin" %>
<%@ Import Namespace="SitefinityWebApp.Model.Session" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
</head>
<body>
<form id="form1" runat="server">
<!-- start of header -->
<section id="header">
<asp:ContentPlaceHolder ID="cph_header" runat="server" />
</section>
<!-- Site Content -->
<section id="contentWrapper">
<asp:ContentPlaceHolder ID="cph_content" runat="server" />
</section>
</form>
</body>
</html>
下面的頁面被加載到內容
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CorpPendingApproval.ascx.cs" Inherits="SitefinityWebApp.userctrls.Admin.Dashboard.Corporate.CorpPendingApproval" %>
<asp:UpdatePanel ID="PendingApprovalList" UpdateMode="Always" runat="server">
<ContentTemplate>
<asp:HiddenField ID="hf_currentPage" runat="server" value="0" />
<asp:HiddenField ID="hf_totalResults" runat="server" value="0" />
<h2>Pending Approvals</h2>
<div class="corporateAdminPagination">
<a ID="topPageBack" class="leftArrow" runat="server" onserverclick="PageBack"></a>
<asp:Label ID="topCurrentPageInfo" Text="" runat="server" />
<a ID="topPageForward" class="rightArrow" runat="server" onserverclick="PageForward"></a>
</div>
<!-- Table Start -->
<table class="corporateAdminPendingApprovals" cellspacing="0">
<!-- Table Heading -->
<!-- Example Binding Setup -->
<asp:Repeater ID="LowPriority" runat="server">
<ItemTemplate>
<tr class="pendingApprovalListItem"
<!-- Repeater Bindings Here -->
</tr>
</ItemTemplate>
</asp:Repeater>
<!-- Table Footer -->
<tr class="pendingApprovalsFooter">
<!-- Footer Pagination -->
<td width="221" class="corporateAdminPagination">
<a ID="bottomPageBack" class="leftArrow" runat="server" onserverclick="PageBack"></a>
<asp:Label ID="bottomCurrentPageInfo" Text="" runat="server" />
<a ID="bottomPageForward" class="rightArrow" runat="server" onserverclick="PageForward"></a>
</td>
</tr>
</table>
<!-- Table End -->
</ContentTemplate>
</asp:UpdatePanel>
代碼背後上述用戶的控制
namespace SitefinityWebApp.userctrls.Admin.Dashboard.Corporate {
public partial class CorpPendingApproval : System.Web.UI.UserControl {
public int CurrentPage {
get {
return int.Parse(hf_currentPage.Value);
}
set {
hf_currentPage.Value = value.ToString();
}
}
public int TotalResults {
get {
return int.Parse(hf_totalResults.Value);
}
set {
hf_totalResults.Value = value.ToString();
}
}
//Sets default page values for pagination results
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
CurrentPage = 0;
TotalResults = GetResultSetCount();
PopulatePageInfoTexts();
PopulatePageWithResultSet();
}
}
//Returns the count of the entire result set
private int GetResultSetCount() {
//Returns List<T>
//Omitted for brevity
}
//Moves the pagination back one page
protected void PageBack(object sender, EventArgs e) {
if (CurrentPage > 0) {
CurrentPage--;
PopulatePageInfoTexts();
PopulatePageWithResultSet();
}
}
//Moves the pagination forward one page
protected void PageForward(object sender, EventArgs e) {
if (CurrentPage < (int)(TotalResults/((CurrentPage + 1) * 20))) {
CurrentPage++;
PopulatePageInfoTexts();
PopulatePageWithResultSet();
}
}
//Displays info about number of results/pages for pagination
private void PopulatePageInfoTexts() {
//Logic omitted for brevity
}
//Displays result set based on current viewing page
private void PopulatePageWithResultSet() {
//Logic omited for brevity
//Bind to repeaters
TopPriority.DataSource = topPriority;
TopPriority.DataBind();
}
}
}
基本上,當單擊pageForward或pageBack按鈕時,它會更改隱藏字段中的值,並使用新的偏移量從DB請求數據,並將該數據綁定到UpdatePanel中的Repeater。我希望它調用服務器,增加當前頁面,並顯示新的結果。這僅在第一次點擊任何按鈕時才起作用。之後,在Chrome的DevTools中查看網絡調用和響應時HTML會正確返回,但是在第一次發佈後,HTML永遠不會在頁面上重新呈現......?
發生這種情況時發生錯誤,它來自jquery.cookie.js。這個文件的include沒有在整個項目中的位置,所以我猜測SiteFinity將它包含在某個捆綁的DLL中。我不知道這是否是問題的根源,但我認爲這與它有關。以下是在DevTools中顯示的錯誤
Uncaught TypeError: undefined is not a function: Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=ctl09_TSM&compress=0&_TSM_CombinedScripts_=%3b%3bT…:559
_checkBrowseAndEditState:function(){browseAndEditState=jQuery.cookie(this._browseAndEditCookieName);
在此先感謝您的幫助!