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

Joshua Olson joshua at waetech.com
Tue Apr 9 17:36:00 CDT 2002


----- Original Message -----
From: "Howard Cheng" <howcheng at ix.netcom.com>
To: <thelist at lists.evolt.org>
Sent: Tuesday, April 09, 2002 6:21 PM
Subject: Re: [thelist] [C#] Inheriting code-behind classes

Howard,

For simplicity, I reduced the code for the .cs file to:

using System;
using System.Web.UI;

namespace xxx
{
     public class Common : Page
     {
         protected void Page_Init(Object Source, EventArgs E)
         {
         }

         protected void Page_Unload(Object Source, EventArgs E)
         {
         }
     }
     public class Page1 : xxx.Common
     {
         private void Page_Load(Object Source, EventArgs E)
         {
           Response.Write("bar");
         }
     }
     public class Page2 : xxx.Common
     {
         private void Page_Load(Object Source, EventArgs E)
         {
           Response.Write("bar");
         }
     }
}

My aspx files are simply:

<%@ Page language="C#" Inherits="xxx.Page1" %>
<%@ Assembly name="xxx" %>

and alternately:

<%@ Page language="C#" Inherits="xxx.Page2" %>
<%@ Assembly name="xxx" %>

The results are as I'd expect, "foo" and "bar".  This indicates that what
you are trying to do is technically possible.

As far as your code goes, it seems like you may have a scoping problem.  In
your classes, you do work against the mydiv control.  But, you've locally
defined the controls in the child class:

public HtmlGenericControl mydiv = new HtmlGenericControl();

So, the next question is, how does the system know to use the mydiv in the
html or the mydiv you've explicitly created in the code?

That should be enough to get you started.  Hollar if you need some more
info.

-joshua





More information about the thelist mailing list