Home All Groups Group Topic Archive Search About

Inheritance of controls & pages

Author
12 Jan 2006 9:31 PM
Ryan
I'm developing a fairly large application in ASP.NET 2.0. In this
applicaiton, I have a combination of .aspx and .ascx pages and controls, each
of which has code-behind files which do my application logic to generate the
interface.

I would like to create a "master" class which would contain methods, etc
that can be accessed by all .aspx and controls within the application. What's
the best way to do this?

I've tried creating a new class that inherits from System.Web.UI.UserControl
and implements new methods, then inheriting from this class when I create new
user controls. This works awesome, because then in any user control, I can say

  me.MyInheritedMethod();

But this does not help for Pages... I'd have to create a seperate class for
Pages to inherit from.

I feel like I understand inheritance well enough, but I can't seem to get my
head wrapped around the best way to accomplish it for both. Do I need to
create a new class that inherits from an interface?

Thanx

Author
13 Jan 2006 12:27 AM
Steve C. Orr
You could put common code in your Master Page.
Another approach is to make a static class and put it in the App_Code folder.

--
I hope this helps,
Steve C. Orr
MCSD, MVP
http://Steve.Orr.net



Show quoteHide quote
"Ryan" wrote:

> I'm developing a fairly large application in ASP.NET 2.0. In this
> applicaiton, I have a combination of .aspx and .ascx pages and controls, each
> of which has code-behind files which do my application logic to generate the
> interface.
>
> I would like to create a "master" class which would contain methods, etc
> that can be accessed by all .aspx and controls within the application. What's
> the best way to do this?
>
> I've tried creating a new class that inherits from System.Web.UI.UserControl
> and implements new methods, then inheriting from this class when I create new
> user controls. This works awesome, because then in any user control, I can say
>
>   me.MyInheritedMethod();
>
> But this does not help for Pages... I'd have to create a seperate class for
> Pages to inherit from.
>
> I feel like I understand inheritance well enough, but I can't seem to get my
> head wrapped around the best way to accomplish it for both. Do I need to
> create a new class that inherits from an interface?
>
> Thanx

Bookmark and Share