Calling DirectMethod within a User Control

  1. #1

    Calling DirectMethod within a User Control

    I'm trying to use the rowexpander on a girdpanel in a user control but I keep getting a javascript error. I think the error is coming from calling the direct method within the user control.

    I have tried using [DirectMethod(IDMode = DirectMethodProxyIDMode.None)] in front of the method but still can't get it working.

    Any help would be appreciated.

    Here is the main page
    
    <%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test._Default" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <%@ Register Src="GridPanel.ascx" TagPrefix="GridP" TagName="GridP" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
        
    <html xmlns="http://www.w3.org/1999/xhtml">
    <%--<html>--%>
    <head id="Head1" runat="server">
    
        <title>Test</title>
    
        <script src="scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    
    
    </head>
    
    <body>
    
        <form id="MyApp" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" Theme="Gray" CleanResourceUrl="false" Namespace="MyApp" AjaxTimeout="60000" />
    
    
            <ext:UserControlLoader ID="uclUserControls" runat="server">
                <Items>
                    <GridP:GridP ID="ctlGridP" runat="server" />
                </Items>
            </ext:UserControlLoader>
    
        </form>
    
    </body>
    </html>
    A this is the code for the user control (.ascx)
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GridPanel.ascx.cs" Inherits="Test.GridPanel" %>
    
    
    <%@ Import Namespace="System.Collections.Generic"%>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
    
       protected void Page_Load(object sender, EventArgs e)
        {
            if (X.IsAjaxRequest)
            {
                //We do not need to DataBind on an DirectEvent
                return;
            }
            
            List<object> data = new List<object>();
            
            for (int i = 1; i <= 10; i++)
            {
                data.Add(new { ID = "S" + i, Name = "Supplier " + i});
            }
            
            this.Store1.DataSource = data;
            this.Store1.DataBind();
        }
    
    
    
        [DirectMethod(IDMode = DirectMethodProxyIDMode.None)]
        public string GetGrid(Dictionary<string, string> parameters)
        {
            // string id = parameters["id"];
            
            List<object> data = new List<object>();
            
            for (int i = 1; i <= 10; i++)
            {
                data.Add(new { ID = "P" + i, Name = "Product " + i });
            }
    
            GridPanel grid = new GridPanel
            {
                Height = 200,
                EnableColumnHide = false,
                Store = 
                { 
                    new Store 
                    { 
                        Model = {
                            new Model {
                                IDProperty = "ID",
                                Fields = 
                                {
                                    new ModelField("ID"),
                                    new ModelField("Name")
                                }
                            }
                        },
                        DataSource = data
                    }
                },
                ColumnModel =
                {
                    Columns = 
                    { 
                        new Column { Text = "Products's Name", DataIndex = "Name" }
                    }
                }
            };
    
            return ComponentLoader.ToConfig(grid);
        }   
    
    
    </script>
    
    
    
    <!DOCTYPE html>
     
    <ext:Window ID="Win" runat="server" >
    
        <Items>
    
                <ext:GridPanel 
                runat="server"             
                Title="Expander Rows with GridPanel"
                Collapsible="true"
                AnimCollapse="true" 
                Icon="Table" 
                Width="600"
                Height="450"
                DisableSelection="true">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Model>
                            <ext:Model runat="server" IDProperty="ID">
                                <Fields>
                                    <ext:ModelField Name="ID" />
                                    <ext:ModelField Name="Name" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">               
                    <Columns>
                        <ext:Column runat="server" Text="Supplier" DataIndex="Name" Flex="1" />
                    </Columns>
                </ColumnModel>            
                <Plugins>
                    <ext:RowExpander runat="server">
                        <Loader runat="server" DirectMethod="#{DirectMethods}.GetGrid" Mode="Component">
                            <LoadMask ShowMask="true" />
                            <Params>
                                <ext:Parameter Name="id" Value="this.record.getId()" Mode="Raw" />
                            </Params>
                        </Loader>
                    </ext:RowExpander>
                </Plugins>            
            </ext:GridPanel>
        </Items>
    </ext:Window>
    Last edited by Daniil; Apr 21, 2015 at 12:01 PM.
  2. #2
    Hi @smithdp,

    There are two solutions.

    1. Please use
    [DirectMethod]
    public string GetGrid(Dictionary<string, string> parameters)
    and
    DirectMethod="#{DirectMethods}.GetGrid"
    or

    2. Please use
    [DirectMethod(IDMode = DirectMethodProxyIDMode.None)]
    public string GetGrid(Dictionary<string, string> parameters)
    and
    DirectMethod="MyApp.direct.GetGrid"
  3. #3
    Thanks Daniil.
    Its working fine now.

Similar Threads

  1. [CLOSED] DirectMethod from inside Dynamic User Control
    By ljankowski in forum 2.x Legacy Premium Help
    Replies: 12
    Last Post: Dec 18, 2013, 1:56 PM
  2. Replies: 2
    Last Post: May 09, 2013, 3:41 PM
  3. Replies: 2
    Last Post: Oct 12, 2011, 7:49 AM
  4. Replies: 0
    Last Post: Oct 19, 2010, 7:39 AM
  5. DirectMethod in user control
    By Ealirene in forum 1.x Help
    Replies: 2
    Last Post: Oct 04, 2010, 5:08 PM

Tags for this Thread

Posting Permissions