Code reuse, code behind, and can't inherit since already inheritsPage

  • Thread starter Thread starter Randall Parker
  • Start date Start date
R

Randall Parker

I've noticed that C# can only inherit from a single class. At the same time, the
CodeBehind in an aspx.cs file inherits from Page.

So what do you all do to reuse code in .aspx.cs classes?

Seems to me one has to create classes and make them members of classes in the aspx.cs
files.

Is that what you all do? (at least those of you who try to get re-use)

Anything else you do?
 
Make all aspx.cs classes inherit from a class which inherits from page.

public class BasePage : Page
{
blah
}

pubic class Index : BasePage
{
OnLoad...
}

or you can use masterPages to do some of this, but that tends to be more for
UI inheritance...

Karl
 
I've noticed that C# can only inherit from a single class. At the same time, the
CodeBehind in an aspx.cs file inherits from Page.

So what do you all do to reuse code in .aspx.cs classes?

Seems to me one has to create classes and make them members of classes in the aspx.cs
files.

Is that what you all do? (at least those of you who try to get re-use)

Anything else you do?
You can also use composition (include another class instance) and pass the
current context (Page.context)
 
Back
Top