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

Howard Cheng howcheng at ix.netcom.com
Tue Apr 9 18:26:00 CDT 2002


At 06:49 PM 4/9/2002 -0400, Joshua Olson wrote:
>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?

I don't know, actually,  but that's how it works in the examples I've seen
and in my practice code (I converted an ASP page into ASP.NET). It seems
that when you name your control in the code-behind code the same as the ID
in the [div id=""] declaration, ASP.NET knows they refer to the same control.

I reduced my stuff to the simplest possible code and guess what, it's still
bad. I wonder if something is screwy with the install.

test.aspx:
<%@ Page Inherits="xxx.Class1" %>
[div id="mydiv" runat="server"/]

test.cs:
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace xxx
{
     public class Class1 : Page
     {
         public HtmlGenericControl mydiv = new HtmlGenericControl();

         private void Page_Load(Object Source, EventArgs E)
         {
             mydiv.InnerHtml = "Hello World!";
         }
     }
}

I'm using VS.NET to compile. It compiles successfully, but test.aspx shows
NOTHING.

Something has to be messed up.

NOW, if I *don't* compile it and use <%@ Page Inherits="xxx.Class1"
src="test.cs" %> I get an error message saying in global.asax saying that
it cannot load type "xxx.Global" (even though it's there in
global.asax.cs). Global.asax contains one line:

<%@ Application Codebehind="Global.asax.cs" Inherits="xxx.Global" %>

Global.asax.cs starts off (this was generated by VS.NET):

namespace xxx
{
     public class Global : System.Web.HttpApplication
     {
     }
}

I'm tearing my hair out over this. Deadlines are creeping closer and I'm
not getting anywhere... sigh.

Thanks.


::::::::::::::::::::::
Howard Cheng
howcheng at ix.netcom.com
AIM: bennyphoebe
ICQ: 47319315




More information about the thelist mailing list