[CLOSED] Experiment with UserControlLoader to user Control instead of UserControl

  1. #1

    [CLOSED] Experiment with UserControlLoader to user Control instead of UserControl

    I went through UserControlLoader and replaced UserControl with Control. The idea was simply to see if it would compile and run because it would allow other controls like a WebControl to load as well. The experiment worked. I'm wondering, why wouldn't you guys consider making this change?

    Index: C:/Users/Michael/Documents/Visual Studio 2012/Projects/Ext.Net/Ext.Net/Ext/UserControlLoader.cs
    ===================================================================
    --- C:/Users/Michael/Documents/Visual Studio 2012/Projects/Ext.Net/Ext.Net/Ext/UserControlLoader.cs    (revision 5348)
    +++ C:/Users/Michael/Documents/Visual Studio 2012/Projects/Ext.Net/Ext.Net/Ext/UserControlLoader.cs    (working copy)
    @@ -84,7 +84,7 @@
                 }
             }
     
    -        private UserControl uc;
    +        private Control uc;
     
             /// <summary>
             /// 
    @@ -100,11 +100,11 @@
             /// <summary>
             /// 
             /// </summary>
    -        public virtual List<UserControl> UserControls
    +        public virtual List<Control> UserControls
             {
                 get
                 {
    -                List<UserControl> controls = new List<UserControl>();
    +                List<Control> controls = new List<Control>();
     
                     if (this.DesignMode)
                     {
    @@ -137,7 +137,7 @@
                             path = dir + "/" + path;
                         }
     
    -                    this.uc = (UserControl)this.Page.LoadControl(path);
    +                    this.uc = (Control)this.Page.LoadControl(path);
     
                         if (this.UserControlID.IsNotEmpty())
                         {
    @@ -180,19 +180,19 @@
     
             #endregion
     
    -        private ItemsCollection<UserControl> items;
    +        private ItemsCollection<Control> items;
     
             /// <summary>
             /// 
             /// </summary>
             [PersistenceMode(PersistenceMode.InnerProperty)]
    -        public virtual ItemsCollection<UserControl> Items
    +        public virtual ItemsCollection<Control> Items
             {
                 get
                 {
                     if (this.items == null)
                     {
    -                    this.items = new ItemsCollection<UserControl>();                                        
    +                    this.items = new ItemsCollection<Control>();                                        
                         this.items.AfterItemAdd += this.AfterUCAdd;
                         this.items.AfterItemRemove += this.AfterUCRemove;
                     }
    @@ -271,7 +271,7 @@
             /// 
             /// </summary>
             [Description("")]
    -        protected virtual void AfterUCAdd(UserControl item)
    +        protected virtual void AfterUCAdd(Control item)
             {
                 if (!this.Controls.Contains(item))
                 {
    @@ -308,7 +308,7 @@
             /// 
             /// </summary>
             [Description("")]
    -        protected virtual void AfterUCRemove(UserControl item)
    +        protected virtual void AfterUCRemove(Control item)
             {
                 if (this.Controls.Contains(item))
                 {
    @@ -362,14 +362,14 @@
         /// </summary>
         public class UserControlAddedEventArgs : EventArgs
         {
    -        public UserControlAddedEventArgs(UserControl control)
    +        public UserControlAddedEventArgs(Control control)
             {
                 this.userControl = control;
             }
     
    -        private UserControl userControl;
    +        private Control userControl;
     
    -        public UserControl UserControl
    +        public Control UserControl
             {
                 get
                 {
    I will note though that the only control I couldn't get this to work with was asp:ContentPlaceholder. I'd hoped I could do this:
        <ext:Panel runat="server" Layout="VBoxLayout">
        <LayoutConfig>
            <ext:VBoxLayoutConfig Align="Stretch" />
        </LayoutConfig>
        <Items>
            <ext:UserControlLoader runat="server">
            <Items>
                <asp:ContentPlaceHolder id="cp" runat="server" />
            </Items>
            </ext:UserControlLoader>
        </Items>
        </ext:Panel>
    Last edited by Daniil; Sep 12, 2013 at 3:00 PM. Reason: [CLOSED]
  2. #2
    Hi

    I went through UserControlLoader and replaced UserControl with Control. The idea was simply to see if it would compile and run because it would allow other controls like a WebControl to load as well. The experiment worked. I'm wondering, why wouldn't you guys consider making this change?
    Can you expalin why do you need it? If you create custom control then why it is not inherited from Ext.Net control? Just Loader doesn't render control, it extracts control's children (children must be Ext.Net controls) and add to Items collection

    I will note though that the only control I couldn't get this to work with was asp:ContentPlaceholder.
    Why not just use Content?
    <ext:Panel runat="server" Layout="VBoxLayout">
    <LayoutConfig>
        <ext:VBoxLayoutConfig Align="Stretch" />
    </LayoutConfig>
    <Content>
          <asp:ContentPlaceHolder id="cp" runat="server" />
    </Content>
    </ext:Panel>
    In this case, top level Ext.Net controls from content placeholder will be interpreted as items
  3. #3
    Quote Originally Posted by Vladimir View Post
    Can you expalin why do you need it? If you create custom control then why it is not inherited from Ext.Net control? Just Loader doesn't render control, it extracts control's children (children must be Ext.Net controls) and add to Items collection
    Three reasons. 1. Third-party libraries of webcontrols, 2. extending existing asp webcontrols, 3. to handle LoadControl(Type t,Object[] parameters).

    Honestly, at present, I don't have any use for any of the three scenarios. I started the experiment to test some issues in terms of the fact that UserControlLoader somehow performs better in participating in layout than Context historically and is constantly advised on the threads, but I haven't spent the time to understand why. When I started making this change, it became apparent to me that those three situations are probably the reason LoadControl returns a Control instead of a UserControl. It became a topic of "well duh; why can't UserControlLoader handle these too?" It seemed perfectly natural to me that it could/should for extensibility. That's my only argument here for presenting the idea. If you guys opt for no here, then I'll rethink if and if/when I ever actually need it.

    Quote Originally Posted by Vladimir View Post
    Why not just use Content?
    <ext:Panel runat="server" Layout="VBoxLayout">
    <LayoutConfig>
        <ext:VBoxLayoutConfig Align="Stretch" />
    </LayoutConfig>
    <Content>
          <asp:ContentPlaceHolder id="cp" runat="server" />
    </Content>
    </ext:Panel>
    In this case, top level Ext.Net controls from content placeholder will be interpreted as items
    This is the current implementation. I was just experimenting to see if the content was causing the other issue I was having in the thread.
  4. #4
    1. Third-party libraries of webcontrols
    Third-party webcontrols will use Ext.Net controls as own children? I am doubt because if you create custom for UserControlLoader (i assume that UserControlLoader accept any controls like you suggested) then you can inherit from Ext.Net control and place directly to Items collection

    As I mentioned before UserControlLoader just extracts Ext.Net children from passed control and added to Items collection. Control is just container for children, it will not be rendered at all, that control as virtual container (like ContentPlaceholder)

    2. extending existing asp webcontrols
    I don't see any sence for it because control is not rendered (any control logic is not executed), just children will be extracted

    3. to handle LoadControl(Type t,Object[] parameters).
    I am not sure that correctly understood it, can you elaborate it?


    I started the experiment to test some issues in terms of the fact that UserControlLoader somehow performs better in participating in layout than Context historically
    Do you mean Content instead Context? We recommend to use always Items instead Content as much as possible. Content can be used if need to interpret Ext.Net children from user control or content placeholder as Items. In this case, you need to set Layout for container. UserControlLoader is not better solution, it is just another way to extract children from user control and add it to Items

    So, the following approaches do the same things (have no advantages before each other)

    <ext:Panel runat="server" Layout="VBoxLayout">
    <Content>
          <uc:MyUserControl runat="server" />
    </Content>
    </ext:Panel>
    <ext:Panel runat="server" Layout="VBoxLayout">
    <Items>
          <ext:UserControlLoader runat="server" Path="MyUserControl.ascx" />
    </Items>
    </ext:Panel>
    We will consider possibility to use Control instead UserControl but at this moment I don't see any advantages of such change, we need to review cases where it can be useful first

Similar Threads

  1. Replies: 2
    Last Post: May 09, 2013, 3:41 PM
  2. Replies: 4
    Last Post: Apr 24, 2013, 4:02 AM
  3. Replies: 7
    Last Post: Jan 29, 2013, 11:59 AM
  4. Replies: 2
    Last Post: Feb 06, 2012, 9:06 AM
  5. how to upload user control dynamicaly on user control
    By archana mahadule in forum 1.x Help
    Replies: 1
    Last Post: Jan 13, 2011, 12:05 PM

Posting Permissions