Help with controls created dynamically.

  1. #1

    Help with controls created dynamically.

    Hello everyone.
    I am just starting this fantastic framework and I need some help with my tests.


    My idea is to create a dynamically direct page of the own page , for example a button to adiconar a particular control and he be rendered at the same time . Only I'm having problems with the fields of Selectbox type , they do not rendererizam the the datasource store dynamically created . Could anyone help me ?
  2. #2
    Hello @Master15! Welcome to Ext.NET forums!

    Have you browsed our examples explorer already? We got a lot of examples that could give you a good idea on how to build controls dynamically, and also how to completely replace a control with something different. Check it out here if you didn't already.

    And here's a example with a combo box generated in code behind:

    <%@ Page Language="C#" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title></title>
        <script runat="server">
            public void Page_Load(object sender, EventArgs e)
            {
                var data = new object[] {
                    new object[] { 1, "one" },
                    new object[] { 2, "two" },
                    new object[] { 3, "three" }
                };
    
                var model = new Model()
                {
                    ID = "cb1mdl1",
                };
                model.Fields.Add(new ModelField() { Type = ModelFieldType.Int, Name = "itemVal" });
                model.Fields.Add(new ModelField() { Type = ModelFieldType.String, Name = "itemDesc" });
    
                var store = new Store()
                {
                    ID = "cb1store1"
                };
    
                store.Data = data;
                store.Model.Add(model);
                store.DataBind();
                
                var cb = new ComboBox()
                {
                    ID = "cb1",
                    DisplayField = "itemDesc",
                    ValueField = "itemVal"
                };
    
                cb.Store.Add(store);
    
                cb.Listeners.Select.Handler = "App.direct.ComboChooseHandler(records[0].data.itemVal, records[0].data.itemDesc);";
                
                cb.AddTo(ctn1);
            }
            
            [DirectMethod]
            public void ComboChooseHandler(int value, string desc)
            {
                X.Msg.Alert("Chosen option", "You've chosen option " + desc + " (" + value + ") on the combo box.");
                X.Msg.Show();
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ResourceManager runat="server" />
            <ext:Container runat="server" ID="ctn1" />
        </div>
        </form>
    </body>
    </html>
    I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Thanks for the fast reply.
    Its help a little bit, but my major problem is not create a dynamic controls, and yes how to populate it later, I mean in a new directmethod.
    Because when I use getcmp, its return a new combobox and not the create, then when i populate it its dont show any items.
  4. #4
    This is a limitation on ASP.NET, about the page's life cycle.

    If you need to check anything on a direct method that the user could potentially change client-side, you also need to pass that information as a parameter to the direct method. Just getCmp() does not help you in this case.

    See this example with feedback communication to direct methods: DirectMethods overview. Particularly interesting there is the example 3. Pass multiple arguments to an DirectMethod.

    This behavior essentially saves the burden of quick direct methods without passin all data loaded and changed by the user via JavaScript.

    The above is just general guidelines, if you have a specific use case you are trying to reproduce, just grab one of the examples on the examples explorer, and adapt it to get as close as you can to what you want to do, and then share the code here. We'll try our best to give you proper advice on how to attain that.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 20
    Last Post: Jul 22, 2013, 7:09 AM
  2. Replies: 0
    Last Post: Apr 22, 2013, 1:20 PM
  3. saving dynamically-created controls' values
    By Skizzot223 in forum 1.x Help
    Replies: 1
    Last Post: Apr 16, 2012, 12:54 PM
  4. [CLOSED] How to clean up dynamically created controls?
    By jchau in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 23, 2011, 9:51 AM
  5. Dynamically created controls cookbooks
    By arodier in forum 1.x Help
    Replies: 15
    Last Post: May 07, 2010, 7:12 PM

Posting Permissions