Fork me on GitHub

UrlPager 示例 - 回发

本示例演示UrlPager在回发后保持当前页状态的功能。
PageChanged event fired, current page index is 15
 First Prev ... 10 11 12 13 14 15 16 17 18 19 ... Next Last

Route definition:

routes.MapPageRoute("UrlPager_Postback",
                "urlpager/demos/{controller}/{pageIndex}",
                "~/UrlPager/Demos/Postback.aspx", false, new RouteValueDictionary { { "controller", "Postback" }, { "pageIndex", null } }, new RouteValueDictionary { { "controller", "Postback" } });

Postback.aspx:

    <%@Register Namespace="Webdiyer.WebControls" Assembly="Webdiyer.UrlPager" TagPrefix="webdiyer"%>
    <form runat="server" id="form1">
    <div>
    <asp:Label runat="server" ID="lb_txt" EnableViewState="false"></asp:Label>
    <asp:Label runat="server" ID="lb_btn" EnableViewState="false"></asp:Label>
        </div>
    <webdiyer:UrlPager runat="server" ID="pager1" RouteName="UrlPager_Postback" InheritsRouteValues="true" PagerItemTemplate="&nbsp;{0}"
                       TotalItemCount="198" OnPageChanged="PageChanged">
        </webdiyer:UrlPager>
    <asp:Button runat="server" ID="btn_test" Text="Post back test" OnClick="TestClick" />
    </form>

Postback.aspx.cs:

using System;
namespace Webdiyer.UrlPagerDemo
{
    public partial class Postback : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void TestClick(object sender, EventArgs e)
        {
            lb_btn.Text = "Button clicked and page postback event fired";
        }
        protected void PageChanged(object sender, EventArgs e)
        {
            lb_txt.Text = "PageChanged event fired, current page index is " + pager1.CurrentPageIndex;
        }
    }
}