Multi Post User Control

Mar 11, 2009
by:   Tim Stanley

Trailing on the lead from Chris Blankenship and his singlepost user control, I created a multi-post user control.  I’ve never been quite satisfied with the results of the recent posts control and Chris’s control filled in enough gaps for me to pursue this further.

I happen to keep my custom controls in /UserCustom instead of /UserControls.  That way, I know these controls are not Blog Engine.Net controls and won’t need to be merged in the future.

Example

Pretty Good URLs

With a little forethought and planning, it’s possible to create URLs that can be around the web for a long time and as Tim Berners-Lee pointed out cool URIs don't change. Choose wisely though, you may have to live with the URLs for much longer than you think, or if your not careful, you may end up with too many URLs pointing to the same content.

Multi Post User Control

Trailing on the lead from Chris Blankenship and his singlepost user control, I created a multi-post user control. I’ve never been quite satisfied with the results of the recent posts control and Chris’s control filled in enough gaps for me to pursue this further.

Nikon Lens Rentals

Before you spend nearly $2000 for a fantastic lens, you may want to rent it to see if it’s really worth it. If you rent this for a week, you can rent this Nikon 70-200mm f2.8 for almost $10 / day. If you can’t afford to own all the Best High End Nikon Lenses, you can still borrow them for a few days for those special occasions when you need the perfect lens.

Usage from ASP

   1: <%@ Register src="../../UserCustom/MultiPosts.ascx" tagname="MultiPosts" tagprefix="uc7" %>
 
   1: <uc7:MultiPosts ID="MultiPosts1" runat="server" 
   2: CategoryList="photography" 
   3: ContentLength="120" 
   4: Count="3" 
   5: DateFormat="{0:MM/dd/yyyy}" 
   6: ShowAuthor="false" 
   7: ShowContent="true"
   8: ShowDate="false"
   9: ShowDescription="true"
  10: ShowTitle="true" />

Usage in Posts or Pages

Remove the space between the bracke and the word usercontrol.

   1: [ usercontrol: ~/UserCustom/MultiPosts.ascx 
   2: ShowDescription=true; 
   3: Count=3; 
   4: ShowContent=false; 
   5: ShowAuthor=true; 
   6: ShowDate=true; 
   7: ShowTitle=true; 
   8: ContentLength=360; 
   9: CategoryList=photography; 
  10: DateFormat={0:MM/dd/yyyy}; ]

Post.cs Add AuthorAbsoluteLink

In order to reduce some of the clutter in the ASCX control template, I created a new property on the Post object to display the Authors link.  If you want to stay with the mainline BE code base, you’ll need to modify the ASCX to set the asp:Hyperlink for AuthorLink to the code shown below.

   1: public Uri AuthorAbsoluteLink
   2: {
   3:     get
   4:     {
   5:         string authorLink = Utils.RemoveIllegalCharacters(Author);
   6:         authorLink = Utils.RelativeWebRoot + "author/" + HttpContext.Current.Server.UrlEncode(authorLink) + BlogSettings.Instance.FileExtension;
   7:         return Utils.ConvertToAbsolute(authorLink);
   8:     }
   9: }

Download

UserCustom.zip (2.37 kb)

Add to favorites Send to a friend Digg It! DZone It! StumbleUpon Technorati Reddit Del.icio.us NewsVine Furl BlinkList