[CLOSED] Reading dynamically created items in fieldset

  1. #1

    [CLOSED] Reading dynamically created items in fieldset

    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">
            <ext:Parameter Name="Width" Value="240" />
            <ext:Parameter Name="LabelWidth" Value="80" />
            <ext:SelectBox ID="DDIdClass" runat="server" DisplayField="ClassTitulo" ValueField="IdClass" FieldLabel="Classifica??o" ondirectselect="DDIdClass_DirectSelect" >
                    <ext:Store ID="Store3" runat="server" DataSourceID="SqlDataSourceClassList">
                            <ext:Model ID="ModelClass" runat="server">
                                    <ext:ModelField Name="IdClass" />
                                    <ext:ModelField Name="ClassTitulo" />
            <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"/>
    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())
    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 6: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
  3. #3
    Just to clarify a bit.

    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
    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");

Similar Threads

  1. Replies: 0
    Last Post: Jun 25, 2014, 7:45 AM
  2. Replies: 1
    Last Post: Nov 05, 2013, 3: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, 12:38 PM
  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, 12:40 PM
  5. set Title in Fieldset dynamically
    By jmilton in forum 1.x Help
    Replies: 4
    Last Post: Mar 27, 2009, 5:39 PM

Tags for this Thread

Posting Permissions