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. Advertising

  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

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

  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

    "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(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, Feb 15, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. onyxring
    Replies:
    0
    Views:
    486
    onyxring
    Feb 15, 2006
  2. =?Utf-8?B?U2ltb24=?=

    Custom Control - Design Time Support

    =?Utf-8?B?U2ltb24=?=, Jan 24, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    326
    =?Utf-8?B?U2ltb24=?=
    Jan 24, 2007
  3. Mark Olbert
    Replies:
    1
    Views:
    514
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
    Feb 17, 2007
  4. David Keenan

    Custom collection design time support

    David Keenan, Oct 9, 2003, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    148
    David Keenan
    Oct 13, 2003
  5. MLibby

    Web Custom Control - Design Time Support ? ? ?

    MLibby, Sep 3, 2004, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    148
    MLibby
    Sep 4, 2004
Loading...

Share This Page