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

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?
 
K

Karl Seguin

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

intrader

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top