spacemonkeys
spacemonkeys

Reputation: 1749

ASP.NET Page inheritance

Looking for advice on the net but not getting very far, so I thought I would ask for some advice. I've seen it done, so know what I want to do, but looking I can work out how it was done

What I want to do, is allow users to modify the layout of an ASPX file, so that they can use it as a letter template, moving address lines, format of the page e.t.c. Now in the example that I was shown, the page inheritied a standard class, and this class had a set of generic functions, such as foreName / sureName / addressLine1 e.t.c, then when designing the ASPX file, if the user wanted addressLine1 to be displayed they would add the tag content = "addressLine1"

Any advice on how to achieve the above would be greatly appreciated, think I'm missing lots of simple stuff

Upvotes: 2

Views: 1446

Answers (1)

Gertjan
Gertjan

Reputation: 880

It might be possible to use a baseclass with the properties they need to define as virtual members. Just create a class (no page, just a class) in you project with the virtual members you want your users to use.

public class BasePage : Page {
  public virtual string Content;
}

In the pages you (or your users) create you need to inherit from that class. Your page would look like:

public class MyPage : BasePage {
  public override string Content = "My Content";

  //Other logic can go here
}

(since the BasePage inherits from the Page class the page will function just like any other Aspx page).

Please note that the base page class needs to be defined in the App_Code folder to be available for other pages/items within you project.

This can also be done for functions.

More reading about virtual members and functions can be done at MSDN

Upvotes: 3

Related Questions