How to defined a UserControl inheirt from Ext.Net.Component with business ruler?

  1. #1

    How to defined a UserControl inheirt from Ext.Net.Component with business ruler?

    My Application have some same component. I want to reuse them.
    So I want to inheirt some UserControl from Ext.Net.Component to use these UserControl in Panel.
    For example, There is a ComboBox used to display category, and such ComboBox used many times.
    So I want to define a UserControl named CategoryComboBox.
    I noticed there is a example in "http://examples1.ext.net/#/Combination_Samples/Applications/Simple_Tasks/".
    But all UserControl in that example are not defined both aspx and aspx.cs files.
    If we can defined UserControl both aspx and aspx.cs files., it will be so quickly to achieve it.
    Could anybody tell me is it can be achieve?
  2. #2
    I found it can not be achieved that define Ext.Net's UserControl with aspx file.
    So I follow the Simple_Tasks example and try to do some new extention of ComboBox, but I failed.
    using System;
    using Ext.Net;
    
    namespace CQU.Net.UserCenter.UX
    {
        [DirectMethodProxyID(IDMode = DirectMethodProxyIDMode.None)]
        public partial class DepartmentComboBox : ComboBox
        {
            private Store store;
    
            protected override void OnLoad(EventArgs e)
            {
                if (!Ext.Net.X.IsAjaxRequest)
                {
                    this.ResourceManager.AddDirectMethodControl(this);
    
                    BuildStore();
                    BuildData();
                }   
            }
    
    
            private void BuildStore()
            {
                this.store = new Store
                {
                    AutoLoad = false,
                    WarningOnDirty = false,
                    Reader =
                    {
                        new ArrayReader
                        {
                            Fields =
                            {
                                new RecordField("abbr", RecordFieldType.String),
                                new RecordField("state"),
                                new RecordField("nick"),
                            }
                        }
                    },
                    SortInfo =
                    {
                        Field = "abbr",
                        Direction = Ext.Net.SortDirection.ASC
                    },
                    Proxy =
                    {
                        new PageProxy()
                    }
                };
    
                this.Store.Add(this.store);
            }
    
            private void BuildData()
            {
                store.DataSource = new object[]
                {
                    new object[] { "AL", "Alabama", "The Heart of Dixie" },
                    new object[] { "AK", "Alaska", "The Land of the Midnight Sun" },
                    new object[] { "AZ", "Arizona", "The Grand Canyon State" },
                    new object[] { "AR", "Arkansas", "The Natural State" },
                    new object[] { "CA", "California", "The Golden State" },
                    new object[] { "WY", "Wyoming", "Like No Place on Earth" } 
                };
                store.DataBind();
            }
        } 
    }
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CQU.Net.UserCenter.UX.WebForm1" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Register Assembly="CQU.Net.UserCenter" Namespace="CQU.Net.UserCenter.UX" TagPrefix="uc" %>
    
    <!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">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <uc:DepartmentComboBox ID="DepartmentComboBox1" runat="server" />
        <ext:FormPanel ID="FormPanelUser" runat="server">
            <Items>
                <uc:DepartmentComboBox ID="Department1" runat="server" />
            </Items>
        </ext:FormPanel>
        </form>
    </body>
    </html>
    I got a error like this "The control with ID 'ctl06' is not IPostBackEventHandler "
  3. #3
    It is no error for the page after I added a js file in to page.
    And I changed cs file .
    cs
    using System;
    using Ext.Net;
    
    namespace CQU.Net.UserCenter.UX
    {
        [DirectMethodProxyID(IDMode = DirectMethodProxyIDMode.None)]
        public partial class DepartmentComboBox : ComboBox
        {
            public DepartmentComboBox()
            {
                BuildStore();
                this.InitLogic();
            }
    
            private Store store;
    
            protected override void OnLoad(EventArgs e)
            {
                if (!Ext.Net.X.IsAjaxRequest)
                {
                    this.ResourceManager.AddDirectMethodControl(this);
    
                    BuildData();
                }    
            }
    
            public const string SCOPE = "CQU.UX.DepartmentComboBox";
    
            private void InitLogic()
            {
                this.Listeners.Render.Fn = DepartmentComboBox.SCOPE + ".init";
                this.Listeners.Render.Scope = DepartmentComboBox.SCOPE;
            }
    
            private void BuildStore()
            {
                this.store = new Store
                {
                    AutoLoad = false,
                    WarningOnDirty = false,
                    Reader =
                    {
                        new ArrayReader
                        {
                            Fields =
                            {
                                new RecordField("abbr", RecordFieldType.String),
                                new RecordField("state"),
                                new RecordField("nick"),
                            }
                        }
                    },
                    SortInfo =
                    {
                        Field = "abbr",
                        Direction = Ext.Net.SortDirection.ASC
                    },
                    Proxy =
                    {
                        new PageProxy()
                    }
                };
    
                this.Store.Add(this.store);
            }
    
            private void BuildData()
            {
                store.DataSource = new object[]
                {
                    new object[] { "AL", "Alabama", "The Heart of Dixie" },
                    new object[] { "AK", "Alaska", "The Land of the Midnight Sun" },
                    new object[] { "AZ", "Arizona", "The Grand Canyon State" },
                    new object[] { "AR", "Arkansas", "The Natural State" },
                    new object[] { "CA", "California", "The Golden State" },
                    new object[] { "WY", "Wyoming", "Like No Place on Earth" } 
                };
                store.DataBind();
            }
        } 
    }
    js
    Ext.ns("CQU.UX");
    
    // ------------------DepartmentComboBox----------------------------------
    CQU.UX.DepartmentComboBox = {
        init : function (combobox) {
            this.combobox = combobox;
        }
    };
    But there are nothing happen when I dropdown the combobox.

    Maybe it is need to set almost all the funtions to new combobox? If that, it is hard to do this job.
  4. #4
    Hi,

    Yes., it's impossible to create a user control inheriting from an Ext.Net.Component.

    Regarding to your code.

    You you define a PageProxy for a Store, you should define an OnRefreshData handler for that store.

    A PageProxy makes a load request to that handler.
  5. #5
    OK,Thank you, It worked as I expected.
    js file is not necessary.
    All properties must be seted code behiend.
    You can closed it. Thank you again.

Similar Threads

  1. Replies: 1
    Last Post: Aug 05, 2011, 10:16 AM
  2. Replies: 3
    Last Post: Jun 16, 2011, 10:34 PM
  3. Replies: 0
    Last Post: Mar 29, 2011, 4:59 PM
  4. Replies: 1
    Last Post: May 22, 2009, 8:38 AM
  5. Replies: 8
    Last Post: Sep 06, 2008, 8:02 PM

Posting Permissions