Design Time Support for custom User Controls

Discussion in 'ASP .Net Building Controls' started by Darren Clark, Jan 13, 2006.

  1. Darren Clark

    Darren Clark Guest

    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
     
    Darren Clark, Jan 13, 2006
    #1
    1. Advertisements

  2. 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
     
    Sergey Poberezovskiy, Jan 16, 2006
    #2
    1. Advertisements

  3. Darren Clark

    Darren Clark Guest

    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

     
    Darren Clark, Feb 15, 2006
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.