DirectEvent or DirectMethod and dynamic UserControl

  1. #1

    DirectEvent or DirectMethod and dynamic UserControl

    Hi.
    I simpled Desktop sample and add a button to user control .
    I will add a click event for button .
    what is my mistake?
    tanks.
    <%@ Page Language="C#" %> <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %> <script runat="server"> [DirectMethod(ShowMask=true)] public void AddNewModule() { Desktop.GetInstance().RemoveModule("add-module"); DesktopModuleProxy control = Ext.Net.Utilities.ControlUtils.FindControl<Ext.Net.DesktopModuleProxy>(this.LoadControl("TabWindows.ascx")); control.RegisterModule(); } </script> <!DOCTYPE html> <html> <head runat="server"> <title>Ext.NET Examples</title> <link href="resources/desktop.css" rel="stylesheet" /> </head> <body> <ext:ResourceManager runat="server"> </ext:ResourceManager> <ext:Desktop ID="Desktop1" runat="server"> <Modules> <ext:DesktopModule ModuleID="add-module"> <Shortcut Name="Render dynamic module" Handler="function() {#{DirectMethods}.AddNewModule();}" X="200" Y="100" TextCls="x-long-label"> </Shortcut> </ext:DesktopModule> </Modules> </ext:Desktop> </body> </html>
    and
    <%@ Control Language="C#"  AutoEventWireup="true" CodeBehind="TabWindows.ascx.cs" Inherits="test2.TabWindows" %>
    
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    
    <ext:DesktopModuleProxy runat="server">
        <Module ModuleID="tab-win">
            <Shortcut Name="Tab Window" />
            <Launcher Text="Tab Window" Icon="Tab" />
            <Window>
                <ext:Window runat="server"
                    Icon="Tab"
                    Width="740"
                    Height="480"
                    ConstrainHeader="true"
                    Border="false"
                    Layout="Fit"
                    Title="Tab Window">
                    <Items>
                        <ext:Panel runat="server" Title="Tab Text 1" Border="false" Html="<p>Something useful would be in here.</p>">
                            <Items>
                                <ext:Button runat="server" ID="btn1" Text="test">                              
                                    <DirectEvents>
                                        <Click OnEvent="btn1_Click"></Click>
                                    </DirectEvents>
                                </ext:Button>
                                <ext:TextField ID="text1" runat="server"></ext:TextField>
                            </Items>
                        </ext:Panel>
                    </Items>
                </ext:Window>
            </Window>
        </Module>
    </ext:DesktopModuleProxy>


    with code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    
    
    namespace test2
    {
        public partial class TabWindows : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
    
            }
            [DirectMethod]
            public void btn11_Click()
            {
               
            }
    
    
            protected void btn1_Click(object sender, DirectEventArgs e)
            {
    
    
            }
        }
    }
    Last edited by Daniil; Oct 24, 2014 at 6:03 AM. Reason: Please use [CODE] tags
  2. #2
    Hi @shm2847,

    Welcome to the Ext.NET forums!

    The short answer - you cannot define DirectEvents and DirectMethods inside a DesktopModuleProxy.

    You can:

    - Define DirectMethods inside the page itself and call it from client side listeners of components inside a DesktopModuleProxy.

    or

    - Refer DirectEvents or DirectMethods using URLs to, for example, HttpHandlers (.ashx) or WebServices (.asmx).
  3. #3

    New

    Tanks for your attentions.
    I change code and this work correctly ,but i have 3 question:
    1- Is this code acceptable?
    2- When i set window close action to Destroy , after windows closed by user , then not opened again .
    3-can I define store in desktop (page) and used of it on User Control?
    very tanks.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="~/Desktop.aspx.cs" Inherits="test2.Desktop" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
    </head>
    <body>
        <ext:ResourceManager runat="server"></ext:ResourceManager>
        <ext:Desktop ID="Desktop1" runat="server" >  
        </ext:Desktop>
    </body>
    </html>


    and
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    
    namespace test2
    {
        public partial class Desktop : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
               //if (some condition)
                DesktopModuleProxy control = Ext.Net.Utilities.ControlUtils.FindControl<Ext.Net.DesktopModuleProxy>(this.LoadControl("ucTest.ascx"));           
                Ext.Net.Desktop des1 = Ext.Net.Desktop.GetInstance();
                des1.Modules.Add(control.Module);
                if (des1.Modules["tab-win"] != null)
                {
                    ucTest ucSimpleControl = (ucTest)LoadControl("ucTest.ascx");
                    if (ucSimpleControl != null)
                    {
                        des1.Controls.Add(ucSimpleControl);                
                    }
                }
            }              
        }
    }
    
    
    and User Control :
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucTest.ascx.cs" Inherits="test2.ucTest" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <ext:DesktopModuleProxy runat="server" PreventAdding="true">
        <Module ModuleID="tab-win">
            <Shortcut Name="Tab Window" />
            <Launcher Text="Tab Window" Icon="Tab" />
            <Window>
                <ext:Window runat="server"  Icon="Tab"   Width="740" Height="480"   Border="false"  Layout="Fit" CloseAction="Destroy"
                    Title="Tab Window" RTL="true" UI="Success">
                    <Items>
                        <ext:FormPanel runat="server" ID="frm1" Border="false" >
                            <Content>
                                <ext:Store ID="stoChgType" runat="server">
                                    <Model>
                                        <ext:Model ID="modChgType" runat="server" IDProperty="ID">
                                            <Fields>
                                                <ext:ModelField Name="ID" />
                                                <ext:ModelField Name="TITLE" />
                                            </Fields>
                                        </ext:Model>
                                    </Model>
                                    <Listeners>
                                        <DataChanged
                                            Handler="if (this.getCount() > 0) {var record = this.getAt(0) || {};#{frm1}.getForm().loadRecord(record);}"
                                            Delay="10" />
                                    </Listeners>
                                </ext:Store>
                            </Content>
                            <Items>
                                <ext:Button runat="server" ID="btn1" Text="test">
                                    <DirectEvents>
                                        <Click OnEvent="btn1_Click"></Click>
                                    </DirectEvents>
                                </ext:Button>
                                <ext:TextField ID="txt1" runat="server" Name="TITLE"></ext:TextField>
                            </Items>
                        </ext:FormPanel>
                    </Items>
                </ext:Window>
            </Window>
        </Module>
    </ext:DesktopModuleProxy>
    with Code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    using System.Data;
    
    namespace test2
    {
        public partial class ucTest : System.Web.UI.UserControl
        {      
            protected void btn1_Click(object sender, DirectEventArgs e)
            {
                DataTable dtChangeType = new DataTable();
                dtChangeType.Columns.Add("ID");
                dtChangeType.Columns.Add("TITLE");
                dtChangeType.Rows.Add("1", "1");
                dtChangeType.Rows.Add("2", "2");
                dtChangeType.Rows.Add("3", "3");
                dtChangeType.Rows.Add("4", "4");            
                stoChgType.DataSource = dtChangeType;
                stoChgType.DataBind();
            }
        }
    }
    Last edited by Daniil; Oct 24, 2014 at 8:34 AM. Reason: Please use [CODE] tags
  4. #4
    1- Is this code acceptable?
    I think yes, it is.

    I have to clarify this phrase.
    The short answer - you cannot define DirectEvents and DirectMethods inside a DesktopModuleProxy.
    It is only actual if a DesktopModuleProxy is registered dynamically by .RegisterModule() call.

    2- When i set window close action to Destroy , after windows closed by user , then not opened again .
    It is not opened again, because it is destroyed on hiding according to the CloseAction="Destroy" setting.

    3-can I define store in desktop (page) and used of it on User Control?
    You can use it on client side in any way.

    Also you could try to use the StoreID property. The StoreID property is available in a GridPanel, for example. So, if define a Store on the page and refer it by the GridPanel's StoreID that is inside the DesktopModuleProxy, I think it might work. Though, I've not tested.

    Though, there is something - you won't be able to access that Store in the DesktopModuleProxy's code behind.

Similar Threads

  1. Replies: 4
    Last Post: Dec 19, 2012, 9:58 AM
  2. [CLOSED] Dynamic userControl load with DirectMethod
    By ViDom in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Oct 02, 2012, 6:03 PM
  3. [CLOSED] Difference between DirectMethod , DirectEvent, Static DirectMethod
    By syllabusarq in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 01, 2011, 11:37 AM
  4. [CLOSED] DirectMethod and UserControl
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jun 21, 2010, 7:15 PM
  5. [CLOSED] [1.0] DirectMethod - Page . UserControl . UserControl
    By Patrick in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Feb 25, 2010, 9:33 AM

Posting Permissions