[CLOSED] Reading dynamically created items in fieldset

  1. #1

    [CLOSED] Reading dynamically created items in fieldset

    Hello!
    I have a fieldset like this:

    <ext:FieldSet ID="FieldSetIndex" runat="server" ColumnWidth="0.4" Title="Escolha uma ou mais op??es de filtro:" MarginSpec="10" ButtonAlign="Right">
        <Defaults>
            <ext:Parameter Name="Width" Value="240" />
            <ext:Parameter Name="LabelWidth" Value="80" />
        </Defaults>
        <Items>
            <ext:SelectBox ID="DDIdClass" runat="server" DisplayField="ClassTitulo" ValueField="IdClass" FieldLabel="Classifica??o" ondirectselect="DDIdClass_DirectSelect" >
                <Store>
                    <ext:Store ID="Store3" runat="server" DataSourceID="SqlDataSourceClassList">
                        <Model>
                            <ext:Model ID="ModelClass" runat="server">
                                <Fields>
                                    <ext:ModelField Name="IdClass" />
                                    <ext:ModelField Name="ClassTitulo" />
                                </Fields>
                            </ext:Model>
                        </Model>            
                    </ext:Store>    
                </Store>
            </ext:SelectBox>
            <ext:TextField ID="TbDocTitulo" runat="server" FieldLabel="Titulo"></ext:TextField>
            <ext:DateField ID="DocData1" runat="server" FieldLabel="De:" Format="dd/m/yyyy" />
            <ext:DateField ID="DocData2" runat="server" FieldLabel="At?:" Format="dd/m/yyyy"/>
        </Items>
    </ext:FieldSet>
    I can add items to it from code behind on the DDIdClass_DirectSelect event... like this:

    (...)
    var tf = new TextField()
    {
        ID = "ID_" + varData["IdCampo"].ToString(),
        Name = Convert.ToString(varData["CamTitulo"].ToString()),
        FieldLabel = Convert.ToString(varData["CamTitulo"].ToString())
    };
    FieldSetIndex.Items.Add(tf);
    (...)
    FieldSetIndex.Render();
    But, when I loop the Items on FieldSetIndex control the dinamically added items dont show up... why?


    protected void BtFiltrar_OnDirectClick(object sender, DirectEventArgs e){
    
    (...)
    
    foreach (var Control in FieldSetIndex.Items)
    {
        if (Control.XType.ToString() == "textfield")
        {
            TextField tf = (TextField)Control;
            if (tf.ID.StartsWith("ID_"))
            {
                
            }
        }
    }
    I can only see 4 items on FieldSetIndex.Items.Count property - where is the item created dinamically?
    Am I missing something?

    Thank you!
    Last edited by Daniil; Jul 08, 2014 at 5:31 AM. Reason: [CLOSED]
  2. #2
    I'm guessing the full scenario of your page since you've only posted a few snippets, but... it appears you're adding the TextFields during one request (DirectEvent), and foreach looping through the .Items in another DirectEvent request.

    Because ASP.NET is stateless, what is done in one Request is forgotten in the next. If you want access to all the items in the collection, the Controls must be recreated during each request and added to the Page's Controls Collection. The <TextField>'s in markup are recreated on each request, and the TextFields added only during the one DirectEvent request are not.

    We've built some functionality to somewhat work-around this "feature" of ASP.NET (and web applications in general), but you'll need to know the .ID of the Control. You can get an instance of dynamically created Fields by calling the following:

    var field = X.GetCmp<TextField>("THE_ID");
    Hope this helps.
    Geoffrey McGill
    Founder
  3. #3
    Just to clarify a bit.

    This
    X.GetCmp<TextField>("THE_ID")
    doesn't return a real control instance. It is only a proxy.

    It loads the data from POST to that control. For example, in the case with a TextField, it will retrieve a Text from POST.

    Except POST there won't be any other real information. For example, you won't be able to access the TextField. Or, for example, if you get a Panel via
    X.GetCmp<Panel>("Panel_ID")
    it won't have any children in the Items collection. Again, only the data from POST, if any.

    So, loading the data from POST to a proxy control is one side of the X.GetCmp<>() feature.

    Another one that a proxy control is useful to set properties and call methods.

    For example, this sets the TextField's Text. It will actually appear on client.
    var field = X.GetCmp<TextField>("TextField_ID");
    field.Text = "New Text";
    This collapses the Panel on client.
    var panel = X.GetCmp<Panel>("Panel_ID");
    panel.Collapse();

Similar Threads

  1. Replies: 0
    Last Post: Jun 25, 2014, 6:45 AM
  2. Replies: 1
    Last Post: Nov 05, 2013, 2:12 AM
  3. [CLOSED] Multicombo created dynamically not showing selected items
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Sep 10, 2013, 11:38 AM
  4. [CLOSED] [1.0] Tabstrip with dynamicly created items - items.count always 0
    By klaus.schwarz in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 07, 2010, 11:40 AM
  5. set Title in Fieldset dynamically
    By jmilton in forum 1.x Help
    Replies: 4
    Last Post: Mar 27, 2009, 4:39 PM

Tags for this Thread

Posting Permissions