PDA

View Full Version : [CLOSED] [#145] Loading User Controls



odyssey
Feb 10, 2013, 6:27 PM
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','AccordionPane ls.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???

Daniil
Feb 11, 2013, 4:51 AM
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.
http://examples2.ext.net/#/Loaders/Component/Direct_Method/

Daniil
Feb 11, 2013, 9:55 AM
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

Vladimir
Feb 11, 2013, 10:34 PM
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