[CLOSED] [#145] Loading User Controls

  1. #1

    [CLOSED] [#145] Loading User Controls

    I have problem loading UserControl from Javascript
    For Example
    <ext:Panel runat="server" ID="Panel1" Width="600" Height="300" Layout="AccordionLayout">
            <Buttons>
                <ext:Button runat="server" Text="Load Panels">
                    <Listeners>
                        <Click Handler ="App.direct.LoadUserControl('Panel1','AccordionPanels.ascx')"></Click>
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:Panel>
    
    
    and here DirectMethod
    
    [DirectMethod]
            public static void LoadUserControl(string containerId, string userControlPath)
            {
               
                X.Js.AddScript(UserControlRenderer.ToScript(new UserControlRendrerConfig
                {
                    UserControlPath = userControlPath,
                    Mode = RenderMode.AddTo,
                    SingleControl = true,//if false throws an error
                    Element = containerId,
                    ControlIdToRender = containerId
                }));
            }
    
    
    and Here contents of AccordionPanels.ascx
    
    <ext:Panel  runat="server" Title="User Brown" Icon="UserBrown">
    </ext:Panel>
    <ext:Panel runat="server" Title="User Green" Icon="UserGreen">
    </ext:Panel>
    <ext:Panel  runat="server" Title="User Red" Icon="UserRed">
    </ext:Panel>
    If SingleControl == "false" it throws an exception of control not found .I am forced to apply extra panel in my UserControl with "layout = accordion" and change layout of my Parent container "mainPanel layout =fit" but this is adding extra container for no reason.Why SingleControl = "false" throws an exception???
    Last edited by Daniil; Feb 12, 2013 at 8:36 AM. Reason: [CLOSED] [#145]
  2. #2
    Hi @odyssey,

    Thank you for the report! We will investigate.

    Also "e" is missed in "UserControlRendrerConfig". Must be "UserControlRendererConfig". We will correct in SVN.

    Maybe, it is better to use a Loader in your case.
    https://examples2.ext.net/#/Loaders/...Direct_Method/
  3. #3
    I missed the ControlIdToRender option in your code.

    This is a control's ID from a user control. So, it really can't find "Panel1" within the user control.

    But it won't work as you need even if remove this setting, because UserControlRender can't render a few items without an interim container.

    We are going to get it working. Created a feature Issue.
    https://github.com/extnet/Ext.NET/issues/145
  4. #4
    Hi,

    We have added Items property to UserControlRendererConfig
    Now you can use
    [DirectMethod]
            public static void LoadUserControl(string containerId, string userControlPath)
            {
                UserControlRenderer.Render(new UserControlRendererConfig
                {
                    UserControlPath = userControlPath,
                    Mode = RenderMode.AddTo,
                    Element = containerId,
                    Items = true
                });
            }
    If Items=true then all Ext.Net top widgets inside user control will be added as separate items to container
    Last edited by Daniil; Feb 12, 2013 at 8:35 AM.

Similar Threads

  1. Replies: 2
    Last Post: May 09, 2013, 3:41 PM
  2. Replies: 5
    Last Post: Nov 03, 2011, 2:39 AM
  3. Replies: 0
    Last Post: Jan 05, 2011, 6:48 AM
  4. [CLOSED] [1.0] Loading User Controls in runtime
    By webclouder in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: May 16, 2010, 8:07 PM
  5. [CLOSED] Dynamic loading of user controls [1.0]
    By SFritsche in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Feb 11, 2010, 6:08 AM

Posting Permissions