Views: 4377
Number of votes: 2
Average rating:

FilteredPageReference v1.1 Released

I know what you are all thinking, v1.0 was only released 2 days ago.  It must be full of bugs and this is a hasty patch release, but this is not the case, I promise Smile.

I didn’t really see the functionality changing much and I certainly didn’t envisage a new release after 2 days but I had a brain wave yesterday and there was a new feature I wanted to slip in.

For those of you who have not read about my new page picking properties please see my previous post.

The Problem

I am using the new page picking controls for a project I am currently working on.

The project is made up of one code base and many PageType’s but these will be shared amongst many different site instance’s as the site will be released globally.

In all of the sites I have worked on I normally have a Settings page which allows me to set up global site properties such as Site search page link,  Site map page link etc etc.

In this particular project each site will have it’s own settings page having values that obviously differ from site to site.

I would like to be able to set the starting point of the tree for a particular property within a particular page type to point to one of the PageReference properties configured in the settings page but the current implementation of the FilteredPageReference properties does not allow this.

The Solution

I have added a new delegate and a public property to the FilteredPageReference.PropertyFilteredPageReferenceSettings class as follows:

   1:  public delegate PageReference PagePickingStartFromDelegate(PropertyInformation propertyInformation);
   3:  public static PagePickingStartFromDelegate StartFromDelegate { get; set; }

I can then set the delegate in code which will allow me to programmatically set the page picking root in code.

If the delegate method returns null or an empty PageReference then the Tree picking settings will be used.  An example of programmatically setting the picking root is below:

   1:  protected void Application_Start(Object sender, EventArgs e)
   2:  {
   3:      FilteredPageReference.PropertyFilteredPageReferenceSettings.StartFromDelegate = SetPagePickingRootPage;
   4:  }
   6:  public PageReference SetPagePickingRootPage(FilteredPageReference.PropertyInformation propertyInformation)
   7:  {
   8:      PageDataCollection pages = DataFactory.Instance.GetChildren(PageReference.StartPage);
  10:      if (pages.Count == 0)
  11:          return PageReference.EmptyReference;
  13:      Random random = new Random();
  14:      int index = random.Next(0, pages.Count - 1);
  15:      return pages[index].PageLink;
  16:  }

The example above is pretty useless but demonstrates the purpose.

The PropertyInformation class which is passed as a parameter to the delegate currently has the following properties:

  • ParentPageId – Parent page id
  • PageId – Page id
  • WorkId – Work id
  • LanguageId – Language id
  • PageTypeId – Page type id
  • PropertyName – Property name

You could then conditionally check properties like the PageTypeId and PropertyName and then set the picking the start the a specific page.

This may or may not be useful to anyone, but I think it’s cool Winking smile

Have feedback?

Please feel free to email or twitter me with any feedback @croweman

    (By Tahir Naveed , 01 August 2011 12:32, Permanent link)

    Nice work Crowe. Is there any way you can set-up the "Page Picking Restrictions" programmatically as you can set-up the start up page using the delegate.

    (By Lee Crowe , 01 August 2011 12:35, Permanent link)

    Hi Tahir

    At present there is no way to do this. What are your exact requirements? I am sure it is something I could possibly add quite easily.


  Please login to post a comment