Problem with dynamic controls creation

  1. #1

    Problem with dynamic controls creation

    Hi everybody, maybe you can help me with this.

    What i'm trying to do is to create control dynamically depending of the type of the data stored in a list (datatable). i.e: Numeric -> NumericField, Text ->Textfield and so on.

    I'm creating the controls successfully, but the problem is when i try to specify the value the control has to be started with. Something a little weird is that it works with the checkboxes and datefields, but not with the others.

    I'm about to get crazy, please help me with this maybe i'm doing something wrong.

    Here's the code


    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e) {
            crearControles();
        }
    
        protected void crearControles()
        {
            string[,] strValores = { { "TextField", "20" }, { "Checkbox", "True" }, { "DateField", "20/12/2008" }, { "NumberField", "10" } };
            for (int i = 0; i < 4; i++)
            {
                switch (strValores[i,0])
                {
                    case "NumberField":
                        NumberField num = new NumberField();
                        num.ID = "ctrl" + i;
                        num.Width = Unit.Pixel(200);
                        num.FieldLabel= strValores[i,0];
                        num.Text = strValores[i,1];
                        agregarControlesAtribTipoEP(num);
                        break;
                    case "TextField":
                        TextField txt = new TextField();
                        txt.ID = "ctrl" + i;
                        txt.Width = Unit.Pixel(200);
                        txt.FieldLabel= strValores[i,0];
                        txt.Text = strValores[i,1];
                        agregarControlesAtribTipoEP(txt);
                        break;
                    case "Checkbox":
                        Checkbox chk = new Checkbox();
                        chk.ID = "ctrl" + i;
                        chk.FieldLabel= strValores[i,0];
                        chk.Checked = Convert.ToBoolean(strValores[i,1]);
                        agregarControlesAtribTipoEP(chk);
                        break;
                    case "DateField":
                        DateField dtf = new DateField();
                        dtf.ID = "ctrl" + i;
                        dtf.FieldLabel= strValores[i,0];
                        dtf.SelectedDate = Convert.ToDateTime(strValores[i,1]);
                        agregarControlesAtribTipoEP(dtf);
                        break;
                    default:
                        TextField ctrl = new TextField();
                        ctrl.ID = "ctrl" + i;
                        ctrl.Width = Unit.Pixel(200);
                        ctrl.FieldLabel= strValores[i,0];
                        ctrl.Text = strValores[i,1];
                        agregarControlesAtribTipoEP(ctrl);
                        break;
                }
            }
        }
    
        protected void agregarControlesAtribTipoEP(Field ctrl)
        {
            Anchor anc = new Anchor();
            anc.Items.Add(ctrl);
            FormLayout1.Anchors.Add(anc);
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        
            <ext:ScriptManager ID="ScriptManager1" runat="server">
            </ext:ScriptManager>
            <ext:Panel ID="Panel1" runat="server" Height="300" Width="400" Title="Dynamic controls" Frame="true">
                <Content>
                    <ext:FormLayout ID="FormLayout1" runat="server">
                    </ext:FormLayout>
                </Content>
            </ext:Panel>
        
    
        </form>
    </body>
    </html>

    IMPORTANT
    ------------------

    By the way, i guess maybe there's something wrong with the user accounts in your site, cause when i logged in first (today) i was registered under vladimir's account although it never happened before, I even made some screenshots of that so you can see it too (take a look to the attachment).


    Thanks in advance!

    -afhi-
  2. #2

    RE: Problem with dynamic controls creation

    Hi,

    I tested your example with latest toolkit code and it works correct.

    Please retest it when 0.7 release will be available.

Similar Threads

  1. [CLOSED] Dynamic Panel Creation
    By state in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 21, 2009, 2:19 PM
  2. Replies: 0
    Last Post: Apr 30, 2009, 12:55 PM
  3. Dynamic Portal Creation
    By iansriley in forum 1.x Legacy Premium Help
    Replies: 0
    Last Post: Jan 21, 2009, 5:53 PM
  4. [CLOSED] Dynamic window creation
    By peterdiplaros in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jan 13, 2009, 3:16 PM
  5. Dynamic Creation Of Controls
    By Steve in forum 1.x Help
    Replies: 4
    Last Post: Dec 01, 2008, 5:46 PM

Posting Permissions