Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Building Controls (http://www.velocityreviews.com/forums/f59-asp-net-building-controls.html)
-   -   Inheriting from User Control (http://www.velocityreviews.com/forums/t758902-inheriting-from-user-control.html)

Vikas Manghani 10-14-2007 04:28 PM

Inheriting from User Control
 
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


Nathan Sokalski 01-08-2008 03:23 AM

Re: Inheriting from User Control
 
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.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

"Vikas Manghani" <VikasManghani@discussions.microsoft.com> wrote in message
news:C74FFD61-C4DF-4435-B3A5-43FB3D73EDB6@microsoft.com...
> 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
>





All times are GMT. The time now is 04:27 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.