You are here:   Blogs
Register   |  Login

Search

Minimize

PPG&A Blogs

Minimize
Jun 30

Written by: Phil Porter
6/30/2010 6:17 AM 

I like things that are easy to implement and that complement the end users experience.  I think I’ve found one that fits this perfectly.  Most users want the option to change the number of records on a show table page and would like the system to remember it the next time they visit the page.  The control Pagination.ascx in the shared folder is common to every show table page and is the perfect candidate to implement this type of functionality.

The key here is to store the page size in a location that is persisted between sessions and can be communicated down to the table control when needed.  First we’ll create a new init event handler for the pagination control.  In the init event create another new event to capture the click event for the page size button.  
 
The page size is persisted to a cookie on the user’s machine and retrieved in the pagination control during the init event.  Communications with the show table page record control is done through a session variable that ISD generates as part of base table control.  The key is to use the UniqueID of the record control to store the page size in the cookie and in the session variable.  The code in the show table record control; this.PageSize = Convert.ToInt32(this.GetFromSession(this, "Page_Size", "10")); retrieves the page size from a session variable.  Depending on how many containers deep the pagination control is depends on how many parent elements you’ll need to bubble up.  In the example below it’s two levels, one for the collapsible element and then the show table control.  The UniqueID will look something like; ctl00$PageContent$ApplicationTableControl
 
Basically the pagination init event fires before the show table record control init event so we can set the page size session variable to adjust for the custom value otherwise the default value is used.
 
Now create the page size button click event to persist the custom page size in a cookie and the current session variable.
 
When the user comes back to the show table page the previous page size should persist.  You’ve just done a single change to the pagination control that should work throughout the entire system with just a few lines of code.
 
C#
[CODE]
public Pagination()
{
 this.Initialize();
 this.Init += new EventHandler(Pagination_Init); // NEW PAGINATION INIT
}
[/CODE]
 
VB
[CODE]
Public Sub New()
            Me.Initialize()
                        ' NEW PAGINATION INIT
            Me.Init += New EventHandler(Pagination_Init)
End Sub
[/CODE]
 
C#
[CODE]
void Pagination_Init(object sender, EventArgs e)
{
  this.PageSizeButton.Click += new EventHandler(PageSizeButton_Click);
 
  if (!this.IsPostBack)
  {
    string strPageSize = BaseClasses.Utils.NetUtils.GetCookie(this.Parent.Parent.UniqueID.ToString() + "Page_Size");
    if (!string.IsNullOrEmpty(strPageSize))
    {
      this.PageSize.Text = strPageSize;
      this.SaveToSession(this.Parent.Parent.UniqueID.ToString() + "Page_Size", strPageSize);
    }
  }
}
[/CODE]
 
VB
[CODE]
Sub Pagination_Init(sender As Object, e As EventArgs)
            Me.PageSizeButton.Click += New EventHandler(PageSizeButton_Click)
 
            If Not Me.IsPostBack Then
                        Dim strPageSize As String = BaseClasses.Utils.NetUtils.GetCookie(Me.Parent.Parent.UniqueID.ToString() + "Page_Size")
                        If Not String.IsNullOrEmpty(strPageSize) Then
                                    Me.PageSize.Text = strPageSize
                                    Me.SaveToSession(Me.Parent.Parent.UniqueID.ToString() + "Page_Size", strPageSize)
                        End If
            End If
End Sub
[/CODE]
 
 
C#
[CODE]
void PageSizeButton_Click(object sender, EventArgs e)
{
  BaseClasses.Utils.NetUtils.SetCookie(this.Parent.Parent.UniqueID.ToString() + "Page_Size", this.PageSize.Text.ToString());
  this.SaveToSession(this.Parent.Parent.UniqueID.ToString() + "Page_Size", this.PageSize.Text.ToString());
}
[/CODE]
 
VB
[CODE]
Sub PageSizeButton_Click(sender As Object, e As EventArgs)
            BaseClasses.Utils.NetUtils.SetCookie(Me.Parent.Parent.UniqueID.ToString() + "Page_Size", Me.PageSize.Text.ToString())
            Me.SaveToSession(Me.Parent.Parent.UniqueID.ToString() + "Page_Size", Me.PageSize.Text.ToString())
End Sub
[/CODE]
 
 
Thank you,
Phil Porter
E-Mail: pporter@ppgainc.com
Phone:
Chicago: 708-497-3039
Atlanta: 678-362-2035

 

Tags:

Archive

Minimize

WARRANTIES

Minimize

SOURCE CODE SAMPLES MAY BE INCLUDED IN SOME BLOGS. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

Other marks and trade names used in this publication are the property of their respective owners.