I'm trying to call the event from buttons that were created dynamically with a foreach
public void adicionarComanda()
{
List<Comanda> lc = ControllerComanda.getComanda();
foreach (Comanda comanda in lc)
{
Button bt = new Button();
bt.Text = comanda.nome_Pessoa;
bt.CssClass = "botoes";
bt.Click += btnNome1_Click;
bt.CommandArgument = comanda.nome_Pessoa;
HtmlGenericControl li = new HtmlGenericControl("li");
li.Controls.Add(bt);
ulBotoes.Controls.Add(li);
}
}
And the event:
protected void btnNome1_Click(object sender, EventArgs e)
{
string nomePessoa = (sender as Button).CommandArgument;
Session["currentUser"] = nomePessoa.ToString();
Response.Redirect("~/Mobile/Pages/produtosCategoria.aspx");
}
How could I solve this problem and make the event work and I be redirected to the desired page? Many thanks to all!