Adding code to a button inside a custom Control.
Hi,
I have a custom control that is an extended table.
In one of the cells i put a button.
I would like to add code to its onclick event.
what i did is this:
tr = new TableRow();
TableCell tc = new TableCell();
Button b = new Button();
b.Text = "Save";
b.Click += new System.EventHandler(this.insert);
tc.Controls.Add(b);
tr.Cells.Add(tc);
this.Rows.Add(tr);
the insert method signiture is:
protected void insert(Object sender, EventArgs e)
For some reason, insert is never called.
I think the reason is that when the button is pressed and a post back occure, all the internal controls inside the cutom control are re created and the button is replaced by a new one.
What should i do?
Thanks.
|