# button\_click event on dynamically created table not working, asp.net(c#)

**URL:** <https://forum.kirupa.com/t/button-click-event-on-dynamically-created-table-not-working-asp-net-c/290222>\
**Category:** open source\
**Created:** [June 11, 2009, 12:54pm UTC](https://forum.kirupa.com/t/button-click-event-on-dynamically-created-table-not-working-asp-net-c/290222 "2009-06-11T12:54:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulineMinayo](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@PaulineMinayo](https://forum.kirupa.com/u/PaulineMinayo)\
**Post date:** [June 11, 2009, 12:54pm UTC](https://forum.kirupa.com/t/button-click-event-on-dynamically-created-table-not-working-asp-net-c/290222/1 "2009-06-11T12:54:04Z")

</div>

Hi happy people,

I have created a dynamic table.  
It has textboxes and buttons. i’d like the button\_click event to fire. But it’s not.  
Below is my code. Please tell me what I am missing. I will really appreciate.

protected void btn\_Click(object sender, EventArgs e)  
{  
Button btn = sender as Button;  
lbl.Text = btn.CommandArgument;  
lbl.Text = “hi”;  
}

```
protected void Button1_Click(object sender, EventArgs e)
{ int i = Convert.ToInt32(DropDownList1.SelectedIndex);

    for ( i = 0; i &lt; DropDownList1.SelectedIndex; i++)
    {
        TableRow tr = new TableRow();
        //create column1
        TableCell td1 = new TableCell();
        Label _label = new Label();
        _label.ID = "lbl" + i.ToString();
        _label.Text = "Add Level Name" + i.ToString();
        td1.Controls.Add(_label);

        // Create column 2
        TableCell td2 = new TableCell();
        TextBox _text = new TextBox();
        _text.ID = "txt_" + i.ToString();
        td2.Controls.Add(_text);

        //create button
        TableCell td3 = new TableCell();
        Button btn = new Button();
        btn.ID = "popup";
        btn.Text = "goddy";
        btn.CommandArgument = "save me";
        btn.Click += new EventHandler(this.btn_Click);
        td3.Controls.Add(btn);

    //add them
        tr.Cells.Add(td1);
        tr.Cells.Add(td2);
        tr.Cells.Add(td3);
        
        Table1.Rows.Add(tr);

    }

```

}
