Design Time Support for custom User Controls

D

Darren Clark

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(UITypeEditor))]
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
 
S

Sergey Poberezovskiy

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
 
D

Darren Clark

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 said:
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 said:
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(UITypeEditor))]
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
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top