Any help would be appreciated —
here is my aspx code –
<div id="div_Detail" class="div_det" runat="server" />
and in my code behind –
protected void Page_Load(object sender, EventArgs e) {
LoadDetail();
}
private void LoadDetail() {
HtmlTable tbl = new HtmlTable();
HtmlTableRow row = new HtmlTableRow();
HtmlTableCell cell = new HtmlTableCell();
Button bUpdate = new Button();
bUpdate.Text = "Update";
bUpdate.Click += this.Update_Click;
cell.Controls.Add(bUpdate);
row.Cells.Add(cell);
tbl.Rows.Add(row);
div_Detail.Controls.Add(tbl);
}
private void Update_Click(object sender, EventArgs e) {
//Do something
}
I see the button on the page with the correct text. But on clicking that button, Update_Click never gets called.
Am I missing something?
Try giving the button an id. The .NET engine needs IDs on controls during postback to associate the control with a given event delegate.
Edit:
This code works fine: