The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
I’ve decided that it would be a good idea to make a short post on something simple, to give you the break from the epic series and posts I’ve been posting lately. So, in this post I’ll explain how to create a simple user control that displays x number of last modified pages. Take a look at the Figure 1 to see what I have in mind (if you don’t care and just want to get the code, you can do it here).
Figure 1 – Site Activity control displays last pages that have been modified with their titles, link to them and time at which they have been modified
The markup I’ve made is rather simple – repeater and unordered list. Here is how the front end of this control looks like:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SiteActivity.ascx.cs" Inherits="MyControls_SiteActivity" %> |
<asp:Repeater ID="siteActivitityRepeater" runat="server"> |
<HeaderTemplate> |
<ul> |
</HeaderTemplate> |
<ItemTemplate> |
<li> |
<asp:HyperLink ID="pageLink" runat="server"></asp:HyperLink> |
<br /> |
<asp:Label ID="pageDate" runat="server"></asp:Label> |
</li> |
</ItemTemplate> |
<FooterTemplate> |
</ul> |
</FooterTemplate> |
</asp:Repeater> |
As I’ve said – nothing special here. We’ll bind the repeater to the data source and on the ItemDataBound bind the pageLink HyperLink control and pageData Label with respective data.
I’ve commented most of the code and its logic is very simple – so I won’t go into much detail here. You’ll see that we are using CmsManager which is the API class responsible for any pages/templates/controls work. This is the method I’ve used to get the list of pages:
CmsManager manager = new CmsManager(); |
int totalRows = 0; |
IList pages = manager.GetPages(0, activityCount, "DateModified", ListSortDirection.Descending, out totalRows); |
The first two arguments are paging arguments : start and count. I’ve specified the control to start at 0 and get the number of modified pages that user specified through ActivityCount property. Then we have the sort expression, which in our case is “DateModified” and when we pass descending sort direction after that – we get exactly what we want – last x number of modified pages. The last output parameter is not used in my code, however API mandates it so I’ve just declared it there.
To get this control working please do following:
<add name="Site Activity" section="Most popular" url="~/MyControls/SiteActivity.ascx" /> |
And that’s it.
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.