[CLOSED] DirectMethod doesn't work

  1. #1

    [CLOSED] DirectMethod doesn't work

    DirectMethod is not working for me,e here is the sample code:

    View (copy from Ext.NET sample : Reconfigure_GridPanel)
    --------------------------------
    <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>"
       %>
    
    <%-- --------------------------------------------------------------------------------
                Register
    -------------------------------------------------------------------------------------%>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    
    
    <%-- --------------------------------------------------------------------------------
                TitleContent
    -------------------------------------------------------------------------------------%>
    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
        Report Title
    </asp:Content>
    
    
    <%-- --------------------------------------------------------------------------------
                MainContent
    -------------------------------------------------------------------------------------%>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <header>
            <style type="text/css">
            
            </style>
            <script runat="server">
                protected void Page_Load(object sender, EventArgs e)
                {
                    this.BindData();
                }
    
                private void BindData()
                {
                    if (X.IsAjaxRequest)
                    {
                        return;
                    }
                }
                
                private static string[] LAST_NAMES = new string[] { "Jones", "Smith", "Lee", "Wilson", "Black", "Williams", "Lewis", "Johnson", "Foot", "Little", "Vee", "Train", "Hot", "Mutt" };
                private static string[] FIRST_NAMES = new string[] { "Fred", "Julie", "Bill", "Ted", "Jack", "John", "Mark", "Mike", "Chris", "Bob", "Travis", "Kelly", "Sara" };
                private static string[] CITIES = new string[] { "New York", "Los Angeles", "Chicago", "Houston", "Philadelphia", "Phoenix", "San Antonio", "San Diego", "Dallas", "San Jose" };
                private static string[] DEPARTMENTS = new string[] { "Development", "QA", "Marketing", "Accounting", "Sales" };
                private static Random RANDOM = new Random();
    
                public class Office
                {
                    public string City { get; set; }
                    public string Manager { get; set; }
                    public int TotalEmployees { get; set; }
                }
    
                public class Employee
                {
                    public string FirstName { get; set; }
                    public string LastName { get; set; }
                    public int No { get; set; }
                    public string Department { get; set; }
                }
    
                private string GetUnigueCity(List<string> usedCities)
                {
                    string city = CITIES[RANDOM.Next(CITIES.Length)];
                    if (usedCities.Contains(city))
                    {
                        return this.GetUnigueCity(usedCities);
                    }
                    else
                    {
                        usedCities.Add(city);
                        return city;
                    }
                }
    
                private string[] GetUnigueName(List<string> usedNames)
                {
                    string firstName = FIRST_NAMES[RANDOM.Next(FIRST_NAMES.Length)];
                    string lastName = LAST_NAMES[RANDOM.Next(LAST_NAMES.Length)];
                    string[] name = new string[] { firstName, lastName };
                    string key = firstName + lastName;
    
                    if (usedNames.Contains(key))
                    {
                        return this.GetUnigueName(usedNames);
                    }
                    else
                    {
                        usedNames.Add(key);
                        return name;
                    }
                }
    
                private object[] GetOfficesData()
                {
                    Office[] data = new Office[7];
                    List<string> usedNames = new List<string>();
                    List<string> usedCities = new List<string>();
    
                    for (int i = 0; i < 7; i++)
                    {
                        string[] name = this.GetUnigueName(usedNames);
                        data[i] = new Office()
                        {
                            City = this.GetUnigueCity(usedCities),
                            Manager = name[0] + " " + name[1],
                            TotalEmployees = RANDOM.Next(10, 25)
                        };
                    }
    
                    return data;
                }
    
                private object[] GetEmployeesData()
                {
                    Employee[] data = new Employee[20];
                    List<string> usedNames = new List<string>();
    
                    for (int i = 0; i < 20; i++)
                    {
                        string[] name = this.GetUnigueName(usedNames);
                        data[i] = new Employee()
                        {
                            FirstName = name[0],
                            LastName = name[1],
                            No = int.Parse(RANDOM.Next(100, 200).ToString() + RANDOM.Next(100, 200).ToString()),
                            Department = DEPARTMENTS[RANDOM.Next(DEPARTMENTS.Length)]
                        };
                    }
    
                    return data;
                }
    
                private AbstractStore GetOfficeStore()
                {
                    Store store = new Store();
                    store.Data = this.GetOfficesData();
                    store.Fields.Add("City", "TotalEmployees", "Manager");
    
                    return store;
                }
    
                private AbstractStore GetEmployeesStore()
                {
                    Store store = new Store();
                    store.Data = this.GetEmployeesData();
                    store.Fields.Add("FirstName", "LastName", "No", "Department");
    
                    return store;
                }
    
                private ColumnBase[] GetOfficesColumns()
                {
                    return new ColumnBase[]
            {
                new Column()
                {
                    Text = "City",
                    DataIndex = "City",
                    Flex = 1   
                },
                new Column()
                {
                    Text = "Total Employees",
                    DataIndex = "TotalEmployees",
                    Width = 140
                },
                new Column()
                {
                    Text = "Manager",
                    DataIndex = "Manager",
                    Width = 120
                }
            };
                }
    
                private ColumnBase[] GetEmployeesColumns()
                {
                    return new ColumnBase[]
            {
                new Column()
                {
                    Text = "First Name",
                    DataIndex = "FirstName",
                    Flex = 1   
                },
                new Column()
                {
                    Text = "Last Name",
                    DataIndex = "LastName",
                    Flex = 1   
                },
                new Column()
                {
                    Text = "Employee No.",
                    DataIndex = "No",
                    Width = 120
                },
                new Column()
                {
                    Text = "Department",
                    DataIndex = "Department",
                    Flex = 1
                }
            };
                }
    
                protected void ShowOfficesButton_Click(object sender, DirectEventArgs e)
                {
                    X.Js.Call("Ext.suspendLayouts");
                    this.GridPanel1.Title = "Offices";
                    this.GridPanel1.Reconfigure(this.GetOfficeStore(), this.GetOfficesColumns());
                    this.ShowOfficesButton.Disabled = true;
                    this.ShowEmployeesButton.Disabled = false;
                    X.Js.Call("Ext.resumeLayouts", true);
                }
    
                protected void ShowEmployeesButton_Click(object sender, DirectEventArgs e)
                {
                    X.Js.Call("Ext.suspendLayouts");
                    this.GridPanel1.Title = "Employees";
                    this.GridPanel1.Reconfigure(this.GetEmployeesStore(), this.GetEmployeesColumns());
                    this.ShowEmployeesButton.Disabled = true;
                    this.ShowOfficesButton.Disabled = false;
                    X.Js.Call("Ext.resumeLayouts", true);
                }            
                
                
            </script>
    
    
        </header>
    
        <%-- --------------------------------------------------------------------------------
                text/javascript
    -------------------------------------------------------------------------------------%>
        <script type="text/javascript">
    
            var load = function (store) {
                store.load();
            }
    
        </script>
        <ext:FormPanel runat="server">
            <Items>
                <ext:Container ID="Container1" runat="server" Width="500" Height="330">
                    <LayoutConfig>
                        <ext:VBoxLayoutConfig Align="Stretch" />
                    </LayoutConfig>
                    <Items>
                        <ext:Container ID="Container2" runat="server" Layout="HBoxLayout">
                            <Items>
                                <ext:Button
                                    ID="ShowOfficesButton"
                                    runat="server"
                                    Text="Show Offices"
                                    OnDirectClick="ShowOfficesButton_Click" />
                                <ext:Button
                                    ID="ShowEmployeesButton"
                                    runat="server"
                                    Text="Show Employees"
                                    OnDirectClick="ShowEmployeesButton_Click"
                                    Margins="0 0 0 10" />
                            </Items>
                        </ext:Container>
                        <ext:GridPanel
                            ID="GridPanel1"
                            runat="server"
                            Margins="10 0 0 0"
                            Flex="1">
                            <ViewConfig EmptyText="Click a button to show a dataset" DeferEmptyText="false" />
                        </ext:GridPanel>
                    </Items>
                </ext:Container>
            </Items>
        </ext:FormPanel>
    </asp:Content>

    Controller
    ------------------------------------
    namespace AMS.Controllers
    {
        public class ReportCompController : Controller
        {
    
            public ActionResult Index()
            {
                return View();
            }
    
    
    
        }
    }
    Last edited by Daniil; Jan 21, 2014 at 4:43 AM. Reason: Please use [CODE] tags, [CLOSED]
  2. #2
    Hi @Paggy,

    Welcome to the Ext.NET forums!

    I don't see any DirectMethod in your code. Please clarify do you mean a DirectEvent?
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @Paggy,

    Welcome to the Ext.NET forums!

    I don't see any DirectMethod in your code. Please clarify do you mean a DirectEvent?

    The button has a direct click below, but it don't work, the server code only work with method page_load.

    OnDirectClick="ShowOfficesButton_Click" />
  4. #4
    The OnDirectClick thing is for WebForms. It is not going to work in MVC.

    In MVC you should refer a Controller's action via an URL.
    http://mvc.ext.net/#/GridPanel_Array...vent_Creation/
  5. #5
    Quote Originally Posted by Daniil View Post
    The OnDirectClick thing is for WebForms. It is not going to work in MVC.

    In MVC you should refer a Controller's action via an URL.
    http://mvc.ext.net/#/GridPanel_Array...vent_Creation/
    Thanks Daniil, I will try it, thanks. ;-)

    Paggy

Similar Threads

  1. [CLOSED] Renderer doesn't work
    By Gisystems in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Oct 09, 2013, 10:30 PM
  2. The Cls on <Menu> doesn't work
    By cjt0226 in forum 2.x Help
    Replies: 1
    Last Post: May 16, 2013, 6:39 AM
  3. Doesn't work via SSLVPN
    By inorder in forum 1.x Help
    Replies: 10
    Last Post: Jun 06, 2012, 7:42 AM
  4. Replies: 4
    Last Post: Apr 03, 2011, 8:21 AM
  5. [1.0RC]MultiHeader doesn't work.
    By firebank in forum 1.x Help
    Replies: 1
    Last Post: Nov 11, 2010, 4:06 PM

Posting Permissions