I'm sorry, actually the code is a bit more complex, see below full code.
Here is how I use the control in asp web page:
<anigwebcontrols
ager id="Pager1" runat="server"
LabelPageCssClass="MyLabel"
ButtonsCssClass="LinkButton"></anigwebcontrols
ager>
Anyway the "class" attribute for the label is missing in the rendered html.
<span id="Pager1"><a class="LinkButton"
href="javascript:__doPostBack('Pager1$_ctl0','')"><<</a><a class="LinkButton"
href="javascript:__doPostBack('Pager1$_ctl1','')"><</a>Pagina <B>1</B> di
<B>1</B><a class="LinkButton"
href="javascript:__doPostBack('Pager1$_ctl3','')">></a><a class="LinkButton"
href="javascript:__doPostBack('Pager1$_ctl4','')">>></a></span>
Best regards
Anig
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Design;
using System.ComponentModel;
using System.IO;
namespace Anig.Web.UI.WebControls
{
[Designer("Anig.Web.UI.WebControls.PagerDesigner"),
ToolboxData("<{0}
ager runat=server></{0}
ager>"),
PersistChildren(true)]
public class Pager : WebControl, INamingContainer
{
private LinkButton CmdFirst;
private LinkButton CmdLast;
private LinkButton CmdNext;
private LinkButton CmdPrev;
private Label LabelPage;
private static readonly string TotalPagesViewstateKey = "TotalPages" ;
private static readonly string CurrentPageViewstateKey = "CurrentPage" ;
public delegate void FirstPageClickedHandler(object sender, EventArgs e);
public delegate void LastPageClickedHandler(object sender, EventArgs e);
public delegate void NextPageClickedHandler(object sender, EventArgs e);
public delegate void PrevPageClickedHandler(object sender, EventArgs e);
// Events
public event FirstPageClickedHandler FirstPageClicked;
public event LastPageClickedHandler LastPageClicked;
public event NextPageClickedHandler NextPageClicked;
public event PrevPageClickedHandler PrevPageClicked;
// Methods
private void CmdFirst_Click(object sender, EventArgs e)
{
this.OnFirstPageClicked(e);
}
private void CmdLast_Click(object sender, EventArgs e)
{
this.OnLastPageClicked(e);
}
private void CmdNext_Click(object sender, EventArgs e)
{
this.OnNextPageClicked(e);
}
private void CmdPrev_Click(object sender, EventArgs e)
{
this.OnPrevPageClicked(e);
}
protected virtual void OnFirstPageClicked(EventArgs e)
{
if (this.FirstPageClicked != null)
{
this.FirstPageClicked(this, e);
}
}
protected virtual void OnLastPageClicked(EventArgs e)
{
if (this.LastPageClicked != null)
{
this.LastPageClicked(this, e);
}
}
protected virtual void OnNextPageClicked(EventArgs e)
{
if (this.NextPageClicked != null)
{
this.NextPageClicked(this, e);
}
}
protected virtual void OnPrevPageClicked(EventArgs e)
{
if (this.PrevPageClicked != null)
{
this.PrevPageClicked(this, e);
}
}
// Properties
[Category("Behavior"),
DefaultValue(true),
Description("Enabled state of first-page link button")]
public bool ButtonFirstEnabled
{
get
{
this.EnsureChildControls();
return this.CmdFirst.Enabled;
}
set
{
this.EnsureChildControls();
this.CmdFirst.Enabled = value;
}
}
[Description("Enabled state of last-page link button"),
DefaultValue(true),
Category("Behavior")]
public bool ButtonLastEnabled
{
get
{
this.EnsureChildControls();
return this.CmdLast.Enabled;
}
set
{
this.EnsureChildControls();
this.CmdLast.Enabled = value;
}
}
[Description("Enabled state of next-page link button"),
DefaultValue(true),
Category("Behavior")]
public bool ButtonNextEnabled
{
get
{
this.EnsureChildControls();
return this.CmdNext.Enabled;
}
set
{
this.EnsureChildControls();
this.CmdNext.Enabled = value;
}
}
[Category("Behavior"),
DefaultValue(true),
Description("Enabled state of previous-page link button")]
public bool ButtonPrevEnabled
{
get
{
this.EnsureChildControls();
return this.CmdPrev.Enabled;
}
set
{
this.EnsureChildControls();
this.CmdPrev.Enabled = value;
}
}
[Category("Appearance"),
Description("CSS Class name applied to the navigation buttons")]
public string ButtonsCssClass
{
get
{
this.EnsureChildControls();
return this.CmdFirst.CssClass;
}
set
{
this.EnsureChildControls();
this.CmdFirst.CssClass = value;
this.CmdPrev.CssClass = value;
this.CmdNext.CssClass = value;
this.CmdLast.CssClass = value;
}
}
[Description("Current page value"),
Category("Behavior"), DefaultValue(1)]
public int CurrentPage
{
get
{
object obj = this.ViewState[Pager.CurrentPageViewstateKey];
return ((obj != null) ? ((int) obj) : 1);
}
set
{
this.ViewState[Pager.CurrentPageViewstateKey] = value;
}
}
[Description("CSS Class name applied to the label page"),
Category("Appearance")]
public string LabelPageCssClass
{
get
{
this.EnsureChildControls();
return this.LabelPage.CssClass;
}
set
{
this.EnsureChildControls();
this.LabelPage.CssClass = value;
}
}
[Description("The text to be shown for the control"),
Category("Appearance"),
DefaultValue("Pagina <B>{0}</B> di <B>{1}</B>")]
public string Text
{
get
{
this.EnsureChildControls() ;
return LabelPage.Text ;
}
set
{
LabelPage.Text = value ;
this.EnsureChildControls() ;
}
}
[Description("Total pages value"),
DefaultValue(1), Category("Behavior")]
public int TotalPages
{
get
{
object obj = this.ViewState[Pager.TotalPagesViewstateKey];
return ((obj != null) ? ((int) obj) : 1);
}
set
{
this.ViewState[Pager.TotalPagesViewstateKey] = value;
}
}
// Methods section
protected override void CreateChildControls()
{
this.CmdFirst = new LinkButton();
this.CmdNext = new LinkButton();
this.CmdPrev = new LinkButton();
this.CmdLast = new LinkButton();
this.LabelPage = new Label();
this.CmdFirst.Text = "<<";
this.CmdFirst.Click += new EventHandler(this.CmdFirst_Click);
this.CmdPrev.Text = "<";
this.CmdPrev.Click += new EventHandler(this.CmdPrev_Click);
this.CmdNext.Text = ">";
this.CmdNext.Click += new EventHandler(this.CmdNext_Click);
this.CmdLast.Text = ">>";
this.CmdLast.Click += new EventHandler(this.CmdLast_Click);
this.LabelPage.Text = "Pagina <B>{0}</B> di <B>{1}</B>" ;
this.UpdateLabel();
this.Controls.Add(this.CmdFirst);
this.Controls.Add(this.CmdPrev);
this.Controls.Add(this.LabelPage);
this.Controls.Add(this.CmdNext);
this.Controls.Add(this.CmdLast);
}
private void UpdateLabel()
{
this.LabelPage.Text = string.Format(this.Text, this.CurrentPage,
this.TotalPages);
}
}
internal class PagerDesigner : ControlDesigner
{
// Fields
protected Pager pager;
// Methods
public override void Initialize(IComponent component)
{
if (component is Pager)
{
base.Initialize(component);
this.pager = (Pager) component;
}
}
}
}