UpdatePanel仅在初始部分PostBack上更新

时间:2014-06-12 13:25:09

标签: c# html asp.net sitefinity jquery-cookie

我有一个母版页,它有各种占位符,可以为不同的内容加载用户控件。标题是一个,主页面是另一个。在主内容用户控件中,它根据需要显示的页面加载各种其他用户控件。

母版页

<%@ 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);

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

出于某种原因,SiteFinity需要jQuery Cookie插件,但未列为资源。包含jQuery Cookie,一切都很好。