extender

I recently had a specific requirement to ‘expire’ some content on a web site. There’s a million ways to do this, but my previous use of ExtenderControl in Windows Forms development sparked my interest when I noticed the Ajax toolkit supports this (mainly for client-side functionality).

After downloading System.Web.Extensions, and about half an hour later I’d got the ‘ExpiringExtender’ Control that can be added to your ASP.NET (2.0+) page to allow content to phase in or out.

The only down side to this approach is that your source code becomes littered with expired code like the Earth’s orbit does with old satellites! This was therefore a quick solution to a specific problem – not an approach I’d advocate if this is a core requirement (you need a good Content Management System with built-in scheduling).

Anyway – here’s the class (chuck it into your App_Code folder if you’re using a Web Site project – as in my example). The code’s pretty simple – just set a couple of properties (defaulting to min and max dates if not supplied) and the control’s visible property gets set appropriately.

/// <summary> /// This control works as a simple Extender to any server or html control to allow crude time-based /// show-hide functionality. NOTE This requires the Ajax Toolkit. /// </summary>[TargetControlType(typeof(Control))]public class ExpiringExtender : ExtenderControl {

/// <summary> /// Gets or sets the show from date. This indicates that the control should be visible from this date/time /// </summary> /// <value>The show from.</value>public DateTime ShowFrom {get { return this.showFrom; }set { this.showFrom = value; } }

/// <summary> /// Gets or sets the show to date. This indicates that the control should be visible to this date/time /// </summary> /// <value>The show to.</value>public DateTime ShowTo {get { return this.showTo; }set { this.showTo = value; } }