I have a generic editor in ASP.NET page for editing lookup values for different database tables.
The code behind uses a base class which handles 99% of the work across all the different lookups in the system.
A C# class is passed in to the base class from the code behind as below.
public class LookupPageBase : System.Web.UI.Page
{
protected IEditableLookupManager LookupManager
{
get
{
return this.lookupManager;
}
set
{
this.lookupManager = value;
}
}
}
public partial class LookupsEditor : LookupPageBase
{
this.LookupManager = new ConcreteManagerClass();
}
A different C# class is passed into the lookup Manager property for each lookup. I could use the factory pattern to avoid a big if then else in the code behind. However, I was wondering if the same effect could be achieved via a subclass of the code behind e.g.
public partial class LookupsEditorSubClass : LookupsEditor
{
public LookupsEditorSubClass() {
base.LookupManager = new ConcreteManagerClass();
}
}
Questions: 1) This would require the code behind class to be dynamically set..... Can the code behind class be dynamically set and is it even possible to inherit from a partial class? 2) If using a factory instead do I just need to accept a big if then else?