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

Howard Cheng howcheng at ix.netcom.com
Tue Apr 9 16:24:00 CDT 2002


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