[CLOSED] UserControl DirectMethod call

  1. #1

    [CLOSED] UserControl DirectMethod call

    I can duplicate your example of calling a DirectMethod defined by a user control from the usercontrol, but I launch user controls differently. The code below mimics your example when referencing the user control SampleUC01.ascx, but how can I get it to work for SampleUC02.ascx.

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Register Src="SampleUC01.ascx" TagName="MyUserControl" TagPrefix="uc" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" DirectMethodNamespace="DM" />
            <script runat="server">
    
                [DirectMethod]
                public void LaunchDialog(string dir, String controlNm)
                {
                    UserControlRenderer.Render(new UserControlRendererConfig
                    {
                        UserControlPath = String.Format("{0}/{1}.ascx", dir, controlNm),
                        SingleControl = true
                    });
                }
            </script>
    
            <script type="text/javascript">
                Dashboard = {
                    launchDialog: function (dir, controlNm, controlId) {
                        var dialog = Ext.getCmp(controlId);
                        if (dialog) {
                            dialog.show();
                        }
                        else {
                            DM.LaunchDialog(dir, controlNm);
                        }
                    }
                }
            </script>
    
            <uc:MyUserControl ID="UserControl1" runat="server" />
    
            <ext:Button runat="server" Text="Open">
                <Listeners>
                    <Click Handler="Dashboard.launchDialog('.', 'SampleUC02', 'Sample02Window');" />
                </Listeners>
            </ext:Button>
    
        </form>
    </body>
    </html>
    SampleUC01.ascx
    <%@ Control Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
    
        [DirectMethod]
        public void Hello01()
        {
            X.Msg.Alert("...", "Hello from user control Sample 01 Window").Show();
        }
    
    </script>
    
    <ext:Window ID="Sample01Window" runat="server" ClientIDMode="Static" Title="Sample 01 Window" Width="200" Layout="FitLayout" CloseAction="Hide">
        <Items>
            <ext:Button ID="SampleButton" runat="server" Text="Call DirectMethod in ascx">
                <Listeners>
                    <Click Handler="#{DirectMethods}.Hello01();" />
                </Listeners>
            </ext:Button>
        </Items>
    </ext:Window>
    SampleUC02.ascx
    <%@ Control Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
    
        [DirectMethod]
        public void Hello02()
        {
            X.Msg.Alert("...", "Hello from user control Sample 02 Window").Show();
        }
    
    </script>
    <ext:Window ID="Sample02Window" runat="server" ClientIDMode="Static" Title="Sample 02 Window" Width="200" Layout="FitLayout" CloseAction="Hide">
        <Items>
            <ext:Button ID="SampleButton" runat="server" Text="Call DirectMethod in ascx">
                <Listeners>
                    <Click Handler="#{DirectMethods}.Hello02();" />
                </Listeners>
            </ext:Button>
        </Items>
    </ext:Window>
    Last edited by Daniil; Oct 16, 2015 at 12:09 PM. Reason: [CLOSED]
  2. #2
    Hi Chris,

    There are two problems.

    1. UserControlRenderer doesn't support rendering of DirectMethods. So, a response of LaunchDialog call doesn't contain client side proxies for the DirectMethod inside the user control.

    2. Even if it would be able to render DirectMethods' client side proxies, it will not work because a user control would not be recreated during a server request and Ext.NET won't be able to find a server side method to execute.

    There is a few quite comprehensive discussions on that.
    http://forums.ext.net/showthread.php?25279
    http://forums.ext.net/showthread.php?26744

    In brief, rendering user controls on the fly and using its code behind DirectMethods is not going to work, unfortunately. In my opinion in such a scenario a user control is considered as a view (in the MVC terminology), i.e. it is not supposed to have server side handlers. In this case server side handler could be moved to web services (.asmx) or HTTP handlers (.ashx).

    Hope this helps.

Similar Threads

  1. Replies: 1
    Last Post: May 29, 2013, 6:00 PM
  2. Replies: 4
    Last Post: Dec 19, 2012, 9:58 AM
  3. Replies: 2
    Last Post: Jan 14, 2011, 5:51 PM
  4. [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
  5. Can't call AjaxMethod in UserControl
    By dbassett74 in forum 1.x Help
    Replies: 2
    Last Post: May 20, 2009, 6:11 PM

Posting Permissions