User Controls in .NET Framework 2.0 Beta

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?
 
S

Sahil Malik

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
 
G

Guest

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?
 
S

Sahil Malik

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top