[thelist] [C#] Inheriting code-behind classes

Matt Liotta mliotta at r337.com
Tue Apr 9 16:41:08 CDT 2002


Alright, I see my confusion. You are trying to extend Page, not Page1.
Whoops. Anyway, what you need to do is make Common abstract.

-Matt

On 4/9/02 2:23 PM, "Howard Cheng" <howcheng at ix.netcom.com> wrote:

> At 02:02 PM 4/9/2002 -0700, Matt Liotta wrote:
>> You can't have two different objects inherit from each other like you are
>> trying to do. Maybe you explain why you want to do that, then we can help
>> you come up with an alternate implementation.
>>
>> -Matt
>
>
> ??? I'm not having them inherit from each other. Maybe if I use more
> distinct names you'll see what I was trying to do.
>
> page1.cs (code-behind for page1.aspx)
> --------
> namespace xxx
> {
>    public class FirstClass : xxx.CommonClass
>    {
>    }
> }
>
> page2.cs (code-behind for page2.aspx)
> --------
> namespace xxx
> {
>    public class SecondClass : xxx.CommonClass
>    {
>    }
> }
>
> common.cs
> ---------
> namespace xxx
> {
>    public class CommonClass : Page
>    {
>    }
> }
>
> I've got two ASPX pages which are very similar in functionality but with a
> couple of key differences. So I wanted to have a base class that inherits
> from System.Web.UI.Page and then two classes, one for each of the ASPX
> pages, inheriting from that base class.
>
> I suppose I *could* make it so that one code-behind page services both
> pages, with branching code in the Page_Load() function, such as:
>
> private void Page_Load(Object Source, EventArgs E)
> {
>    if (Request.Path == "page1.aspx")
>    {
>        ...
>    }
>    else if (Request.Path == "page2.aspx")
>    {
>        ...
>    }
> }
>
> but I think it's better to separate them. Does that makes sense?
>
>
> ::::::::::::::::::::::
> Howard Cheng
> howcheng at ix.netcom.com
> AIM: bennyphoebe
> ICQ: 47319315




More information about the thelist mailing list