Home All Groups Group Topic Archive Search About

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

Author
1 Nov 2005 6:28 PM
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?

Author
1 Nov 2005 6:41 PM
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

--
MY ASP.Net tutorials
http://www.openmymind.net/

Show quoteHide quote
"Randall Parker" <NOtechieSPAMpundit_please@future_avoidjunk_pundit.com>
wrote in message news:uyFrWIx3FHA.2532@TK2MSFTNGP09.phx.gbl...
> 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?
Are all your drivers up to date? click for free checkup

Author
1 Nov 2005 6:59 PM
intrader
On Tue, 01 Nov 2005 10:28:40 -0800, Randall Parker wrote:

> 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)

Bookmark and Share