[CLOSED] Best practive for creating custom/composite controls

  1. #1

    [CLOSED] Best practive for creating custom/composite controls

    Hi,

    I've seen a few nice examples in ExtJs of creating custom components by extending existing ones. I'd like to do something similar with Ext.Net, but not sure where to begin. I've seen a few threads/posts but some are old now or specific such as extending trees or grids.

    In my scenario, I have a border layout with:
    1) The center containing some specific HTML (and asp.net/Ext.net controls) - basically an ITemplate
    2) The south containing a grid

    Instantiating this custom control would simply set properties to say what part of the center panel's HTML will be shown, hidden, rendered etc (or even just given a control to render). The center panel is therefore internally generated based on all these properties.

    The grid panel, similarly, is internally wired up.

    For now I've been doing this as a helper class that just builds the required UI, passing in all the class parameters in the constructor to the helper and/or via properties on that helper. This works quite well in my following scenarios:

    - ASPX pages where the entire UI is dynamically rendered in code behind
    - ASPX pages or controls where this portion of the UI is rendered dynamically inside a container
    - ASHX handlers that call the same class and returns an XControl (as you helped me in a previous thread)*
    - Unit testing (Nunit)

    * Just for clarity, that ASHX example involves something like this in the ProcessRequest method:

        new DirectResponse(BuildUI().ToScript(RenderMode.AddTo, _outputContainerId)).Return();
    (Where BuildUI returns an XControl)

    The one scenario where the helper class approach doesn't work is of course if we want to declare this via markup.

    So I wonder if there is a better way to do this. Inheriting borderlayout does not feel right, as what I am creating is not a layout. So should I inherit Container and internally create the border layout with the center and south regions at the right time (what is that right time? the Render method?) Or, looking at the way BorderLayout is defined, it is 4 partial classes with builders etc. Would I need to implement something similar?

    This isn't super urgent, as the helper class works in many cases, but I'd be interested to know the right pattern(s) to follow in Ext.Net. If there is existing documentation, examples or forum threads already covering this, please let me know.

    Thanks!
    Last edited by Daniil; Jan 04, 2011 at 11:50 AM. Reason: [CLOSED]
  2. #2
    The "similar threads" section below my original post showed a topic I'd not found through searches before. That led me to the Feed Viewer combination sample.

    That one is interesting as you have a MainPanel class which contains the other components.

    MainPanel inherits Panel and in its constructor it builds the Preview, Grid and other stuff.

    That looks close to an approach I could follow. One question: if building the child components is to be done in the constructor, I guess I can't have public properties to set various things, I'd have to pass that into a constructor? Or are there options to render the child controls later than inside the constructor?
  3. #3
    Hi,

    Sorry for the late response.

    Inheriting borderlayout does not feel right, as what I am creating is not a layout.
    Yes, never inherit from layout classes. It is not widget and you must to provide javascript class which implements layout logic

    That looks close to an approach I could follow. One question: if building the child components is to be done in the constructor, I guess I can't have public properties to set various things, I'd have to pass that into a constructor? Or are there options to render the child controls later than inside the constructor?
    Well, please see existing widgets:
    - if you need to define child control and developer must have ability to choose concrete class from intellisense in the markup (like Menu property of the button, developer can choose from Menu, DateMenu or ColorMenu) then use ItemsCollection generic class and use ItemCollectionJsonConverter converter (define in ConfigOption attribute). Please see Menu property in the ButtonBase.cs class
    - if you have already defined control but you want to add ability to override its properties then use LazyControlJsonConverter converter. Please see Menu property of MenuPanel class
    Vladimir Shcheglov
    Sr. Developer
  4. #4
    Thanks for those pointers. That is helpful.

Similar Threads

  1. [CLOSED] Creating custom control on server side
    By AnulekhaK in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Feb 21, 2012, 10:15 AM
  2. [CLOSED] Creating custom control
    By jchau in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Dec 29, 2010, 6:03 PM
  3. [CLOSED] creating a custom class?
    By smmille1 in forum 1.x Legacy Premium Help
    Replies: 10
    Last Post: Jul 09, 2010, 9:31 PM
  4. Replies: 6
    Last Post: Sep 01, 2009, 1:06 PM
  5. Creating Controls
    By fabiomarcos in forum Feature Requests
    Replies: 2
    Last Post: Dec 22, 2008, 11:16 AM

Tags for this Thread

Posting Permissions