PDA

View Full Version : [CLOSED] ComponentLoader with UserControl containing Ext.Net control with DirectMethods



Moltas
Apr 03, 2012, 10:16 AM
Hi!

I have a question about the new ComponentLoader.
How do I trigger a UserControl LifeCycle when I load it dynamic with ComponentLoader?

Default.aspx

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="Ext.Net" %>
<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
<!DOCTYPE html>
<script runat="server">
[DirectMethod]
public static string LoadUserControl(string parameters)
{
return ComponentLoader.ToJson("~/WebUserControl1.ascx");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:Panel
runat="server"
Height="200"
Width="500"
Layout="FitLayout"
Title="Load UserControl from the Page (static DirectMethod, manual loading)">
<Loader
runat="server"
AutoLoad="false"
DirectMethod="#{DirectMethods}.LoadUserControl"
Mode="Component">
<LoadMask ShowMask="true" />
</Loader>
<Buttons>
<ext:Button runat="server" Text="Load" Icon="PluginGo">
<Listeners>
<Click Handler="this.up('panel').load();this.disable();" />
</Listeners>
</ext:Button>
</Buttons>
</ext:Panel>
</body>
</html>


WebUserControl1.aspx

<%@ Control Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
public class WebUserControl1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void CreateChildControls()
{
base.CreateChildControls();
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
}

[DirectMethod]
public static void HelloWorld()
{
X.Msg.Alert("MyComponent", "Hello World!");
}
}
</script>
<ext:Container ID="Container1" runat="server" Layout="FitLayout" Border="false"
Padding="4">
<Items>
<ext:Panel runat="server" Layout="VBoxLayout">
<Items>
<ext:Label ID="Label1" runat="server" Text="Press the button" />
<ext:Button ID="Button1" runat="server" Width="100" Height="20" Text="Say...">
<Listeners>
<Click Handler="#{DirectMethods}.HelloWorld();" />
</Listeners>
</ext:Button>
</Items>
</ext:Panel>
</Items>
</ext:Container>

Vladimir
Apr 03, 2012, 10:36 AM
ComponentLoader doesn't render user control (user control cannot be added to Items), it extracts components and render those components
UserControl will not participate in rendering

Also please note that static direct method cannot be defined inside user control, only page can contain static direct methods
If you need to perform some action before rendering ten try this code


<%@ Control Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
protected void OnPreRender(object sender, EventArgs e)
{
base.OnPreRender(e);


Button1.Text = DateTime.Now.ToShortDateString();
}
</script>
<ext:Container ID="Container1" runat="server" Layout="FitLayout" Border="false"
Padding="4" OnPreRender="OnPreRender">
<Items>
<ext:Panel runat="server" Layout="VBoxLayout">
<Items>
<ext:Label ID="Label1" runat="server" Text="Press the button" />
<ext:Button ID="Button1" runat="server" Width="100" Height="20" Text="Say...">
</ext:Button>
</Items>
</ext:Panel>
</Items>
</ext:Container>