View Full Version : [CLOSED] Reading dynamically created items in fieldset

Jul 01, 2014, 7:56 PM
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!

Jul 01, 2014, 9:23 PM
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.

Jul 08, 2014, 5:44 AM
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");