Inheriting from User Control

V

Vikas Manghani

Hi
I have a base user control that is inherited from System.Web.UI.UserControl.
It has a single button on it. I want to derive few other controls from this
base user control.
I am using Visual Studio 2005 (ASP.Net 2.0). But its not as simple as
setting the right base classes for the code behind class and setting the
Inherits attribute in the aspx page.
If I create the usercontrol as a class in App_Code and inherit my classes
from it, it works. The problem is that if the class is in App_Code I cannot
have a UI to it, i.e. have a button on its surface.
Can anyone tell me how do I do it?

Thanks in advance
Vikas Manghani
 
N

Nathan Sokalski

You normally do not inherit a UserControl, because the code that adds the
controls in the *.ascx file is done using a Template in the UserControl
class. Something that you can do, however, is the following:

Create another UserControl and use your original UserControl in it
declaratively just like you would a Label or Image or other control that is
built into ASP.NET. If there is code in the codebehind that you want to use
in both UserControls, place that code in a separate.

If you want to include the UserControl in a CustomControl, simply add it
dynamically the same way you would for one of the controls built into
ASP.NET. For example:

Dim myctrl As New MyCtrl()

And then assign values to any of the properties. Hopefully this will help
you with your problem.
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top