[CLOSED] ComponentLoader with UserControl containing Ext.Net control with DirectMethods

  1. #1

    [CLOSED] ComponentLoader with UserControl containing Ext.Net control with DirectMethods

    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>
    Last edited by Daniil; Apr 09, 2012 at 6:59 PM. Reason: [CLOSED]
  2. #2
    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>
    Vladimir Shcheglov
    Sr. Developer

Similar Threads

  1. [CLOSED] ComponentLoader inconsistency
    By RCN in forum 2.x Premium Help
    Replies: 10
    Last Post: Jun 07, 2012, 12:24 PM
  2. [CLOSED] ComponentLoader issue
    By RCN in forum 2.x Premium Help
    Replies: 3
    Last Post: Apr 12, 2012, 9:28 PM
  3. XRender call DirectMethods from UserControl
    By vucuongkg in forum 2.x Help
    Replies: 1
    Last Post: Mar 19, 2012, 10:58 AM
  4. [CLOSED] ComponentLoader - DirectEvents
    By PatrikG in forum 2.x Premium Help
    Replies: 1
    Last Post: Mar 15, 2012, 1:20 PM
  5. [CLOSED] Get ext control inside UserControl
    By methode in forum 1.x Premium Help
    Replies: 2
    Last Post: Dec 22, 2008, 1:24 PM

Tags for this Thread

Posting Permissions