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)
-   -   Design Time Support for custom User Controls (http://www.velocityreviews.com/forums/t758137-design-time-support-for-custom-user-controls.html)

Darren Clark 01-13-2006 08:37 AM

Design Time Support for custom User Controls
 
Is there any way to get the UserControl designer(or my own designer) to
create a class other than UserControl at design time? Or to find out what the
actual class of a UserControl is at design time?

Specifically the situation I have is this:

First the classes...

public abstract class A
{
}

public class B<T>: UserControl where T: A
{
}

public class C: A
{
}

public class D: B<C>
{
}

public class E: D
{
}

public class F: WebControl
{
[Editor(typeof(MyPropertyEditor),typeof(UITypeEdito r))]
public string MyProperty;
}

Now....

I have a user control class E that inherits from D, which in turn inherits
from B<C>(my control could just as well inherit directly from B<C> but I
suspect that may make solving my problem even harder). At this point the
designer works and everything is happy. I drop a WebControl of type F onto my
user control. When the editor MyPropertyEditor is invoked, the statement
"context.NamingContainer.ToString()" returns "System.Web.UI.UserControl".
This indicates that at design time the container is a basic UserControl and
not class E, which is not surprising.

My problem is that in the disigner for F, I want to find out what C is. In
order to do this I need to know the true class of the UserControl descendent
that my WebControl was dropped on.

I added the generics in case that makes a difference, but I don't think it
does. The simple question is really "If I have an intermediate class between
UserControl and my actual control, how can I find out what that intermediate
class is at design time?"

Darren Clark
Lead Software Architect
Ecast, Inc.
http://www.ecastinc.com


Sergey Poberezovskiy 01-16-2006 02:21 AM

RE: Design Time Support for custom User Controls
 
You could check the class type in a variety of ways. Try the following:

myClassVariable.GetType().FullName

if (myClassVariable is myClass){}

to name a few

"Darren Clark" wrote:

> Is there any way to get the UserControl designer(or my own designer) to
> create a class other than UserControl at design time? Or to find out what the
> actual class of a UserControl is at design time?
>
> Specifically the situation I have is this:
>
> First the classes...
>
> public abstract class A
> {
> }
>
> public class B<T>: UserControl where T: A
> {
> }
>
> public class C: A
> {
> }
>
> public class D: B<C>
> {
> }
>
> public class E: D
> {
> }
>
> public class F: WebControl
> {
> [Editor(typeof(MyPropertyEditor),typeof(UITypeEdito r))]
> public string MyProperty;
> }
>
> Now....
>
> I have a user control class E that inherits from D, which in turn inherits
> from B<C>(my control could just as well inherit directly from B<C> but I
> suspect that may make solving my problem even harder). At this point the
> designer works and everything is happy. I drop a WebControl of type F onto my
> user control. When the editor MyPropertyEditor is invoked, the statement
> "context.NamingContainer.ToString()" returns "System.Web.UI.UserControl".
> This indicates that at design time the container is a basic UserControl and
> not class E, which is not surprising.
>
> My problem is that in the disigner for F, I want to find out what C is. In
> order to do this I need to know the true class of the UserControl descendent
> that my WebControl was dropped on.
>
> I added the generics in case that makes a difference, but I don't think it
> does. The simple question is really "If I have an intermediate class between
> UserControl and my actual control, how can I find out what that intermediate
> class is at design time?"
>
> Darren Clark
> Lead Software Architect
> Ecast, Inc.
> http://www.ecastinc.com
>


Darren Clark 02-15-2006 10:00 PM

RE: Design Time Support for custom User Controls
 
This is a bit more complicated. I'm not looking for how to find out the class
of an object, but rather how to get the designer to instantiate an object of
a class other than UserControl.

If I had something to call GetType() on, I'd be happy.

The issue is that I have a class that inherits from UserControl, and another
class that inherits from that class. I then drop a WebControl onto that user
control descendent. In the designer for the WebControl the NamingContainer is
an instance of UserControl, not of my own class.

I'm actually fine with the designer using a UserControl instance to design
on if I have to, but I still need to know what the actual class is.

Darren Clark
Lead Architect
Ecast, Inc.
http://www.ecastinc.com

"Sergey Poberezovskiy" wrote:

> You could check the class type in a variety of ways. Try the following:
>
> myClassVariable.GetType().FullName
>
> if (myClassVariable is myClass){}
>
> to name a few
>
> "Darren Clark" wrote:
>
> > Is there any way to get the UserControl designer(or my own designer) to
> > create a class other than UserControl at design time? Or to find out what the
> > actual class of a UserControl is at design time?
> >
> > Specifically the situation I have is this:
> >
> > First the classes...
> >
> > public abstract class A
> > {
> > }
> >
> > public class B<T>: UserControl where T: A
> > {
> > }
> >
> > public class C: A
> > {
> > }
> >
> > public class D: B<C>
> > {
> > }
> >
> > public class E: D
> > {
> > }
> >
> > public class F: WebControl
> > {
> > [Editor(typeof(MyPropertyEditor),typeof(UITypeEdito r))]
> > public string MyProperty;
> > }
> >
> > Now....
> >
> > I have a user control class E that inherits from D, which in turn inherits
> > from B<C>(my control could just as well inherit directly from B<C> but I
> > suspect that may make solving my problem even harder). At this point the
> > designer works and everything is happy. I drop a WebControl of type F onto my
> > user control. When the editor MyPropertyEditor is invoked, the statement
> > "context.NamingContainer.ToString()" returns "System.Web.UI.UserControl".
> > This indicates that at design time the container is a basic UserControl and
> > not class E, which is not surprising.
> >
> > My problem is that in the disigner for F, I want to find out what C is. In
> > order to do this I need to know the true class of the UserControl descendent
> > that my WebControl was dropped on.
> >
> > I added the generics in case that makes a difference, but I don't think it
> > does. The simple question is really "If I have an intermediate class between
> > UserControl and my actual control, how can I find out what that intermediate
> > class is at design time?"
> >
> > Darren Clark
> > Lead Software Architect
> > Ecast, Inc.
> > http://www.ecastinc.com
> >



All times are GMT. The time now is 08:43 AM.

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