I have a class hierarchy where IObject is the base class for product and customer. I want to define a base page in asp.net which shoud contain generic code. The generic page displays the name of the object and allows user to delete the object by asking for confirmation. The page has to be written against the IObject type. I am trying to define a base page in a below manner but it is giving a compile time error:
public class BaseDeletePage<T> : System.Web.UI.Page
where T:IObject
{
}
It is giving the following compilation error: “Make sure that the class defined in this code file matches the ‘inherits’ attribute, and that it extends the correct base class (e.g. Page or UserControl)”
The generic problem statement is: How to define a parameterized web page class, which could be used by other pages as a base class.
Since you already have an IObject^ interface defined for products and customers, I would recommend simply passing that via a property, instead of giving the class a type parameter.
So that would be:
^ And may I suggest a different interface name? IObject is a bit misleading.
[edit] What Joel Coehoorn wrote is correct. The root problem is that you can’t instantiate a BaseDeletePage, because it doesn’t know what T is. My answer here is that you don’t need a type parameter at all. You simply need a base class that can handle something giving it a reference to the object to be deleted, and that can be done via a property.