User Controls in .NET Framework 2.0 Beta

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

when i used VS Web Express, i created a custom user control .ascx
it doesn't allow to inherit other base classes than System.Web.UI.UserControl.

i have a base class called =>
public class PortalModuleControl : System.Web.UI.UserControl

Then i try to inherit my .ascx class to PortalModuleControl class.
public partial class MyControl : ASPNetPortal.PortalModuleControl


The compiler generate the following error:
Partial declarations of 'ASPNetPortal.MyControl' must not specify different
base classes

Anyone know why it doesn't work?
 
Partial classes is a new feature in .NET framework 2.0. Basically it means
that you have two files which contain definition for the same class. i.e.
one class being split up into two or more files.

The reason it doesn't work here is, they UserControl stuff now works in a
code beside model rather than code behind model. So basically the ascx is a
class that inherits from UserControl, but you took the partial class (code
beside) and made it inherit from something else - therefore it won't work.

- Sahil Malik
You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik
 
hi Sahil,

Thanks for the reply. I have another question. The reason i code it this
way, is becuase i want each usercontrol i created to encapsulate the same
additional information.

for example:

public class PortalModuleControl : System.Web.UI.UserControl
{
int portalID;
}

public partial class MyControl : ASPNetPortal.PortalModuleControl

public partial class MyControl2 : ASPNetPortal.PortalModuleControl

In the above case, i don't need to explicitly define the portaID in both
MyControl
and MyControl2 class. Hence, i can create some function in my base class
PortalModuleControl and share among MyControl and MyControl2. Do you have
any suggestion that how i should go about this in .NET Framework 2.0?
 
Heng,

The ascx front end supports a page directive called "INHERITS".

You would need to create a new class that inherits from
System.Web.UI.UserControl, put in this behavior there, and make sure both
your codebeside and ascx inherit from that custom class.

- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik
 
Back
Top