View Full Version : Load Components Dynamically

Sep 26, 2017, 3:08 PM

I have created a few Checkboxes dynamycally, but I dont find out how can I load them to set them true.

Here is my code to create the CheckBoxes and it works pretty nice:

string categoria = Calzado;
foreach (Familia familia in Familias)
string nombrefamilia = familia.Nombre;
Ext.Net.Checkbox checkfamilia = new Ext.Net.Checkbox();
checkfamilia.ID = nombrecategoria.TrimEnd() + i;
checkfamilia.BoxLabel = nombrefamilia;
checkfamilia.MarginSpec = "0 0 0 60";
checkfamilia.Cls = "normalbox";


As a result I get this:

Now I want to set checked=true in every checkbox below the checkbox "TODO" when I press it, but I cant find the way to do it because i cant load them:

public void Marcartodas(object sender, DirectEventArgs e)
int categoriaID = Int32.Parse(e.ExtraParams["cat"].TrimEnd());

DataBaseAccess dataBaseAccess = new DataBaseAccess(conexionBD);

CategoriaDao cat = new CategoriaDao(dataBaseAccess);
Categoria categoria = cat.getById(categoriaID);

FamiliaDao Fam = new FamiliaDao(dataBaseAccess);
List<Familia> Familias = Fam.GetByCategoria(categoriaID);
int i = 0;
foreach (Familia familia in Familias)
¿¿¿¿¿¿(categoria.nombre + i).Checked = true????


Sep 26, 2017, 5:26 PM
Hello @Pascu!

What you create dynamically (from C# code on page load) will not be just available the next code behind call, just cause their scope is lost between requests in server-side.

You would have to recall them again from the new code behind call before you could make changes to it.

I'm afraid this is as far as we can get without a proper and runnable test case following our More Information Required (https://forums.ext.net/showthread.php?10205) guidelines and templates.

Hope this helps!

Sep 27, 2017, 2:04 PM
So, There's no way to access to the checkboxes created dynamically?

Edit: I found it

foreach (Familia familia in Familias)
string vg = categoria.Nombre.TrimEnd() + i;
Checkbox check = (Checkbox)FindControl(vg);
check.Checked = true;