I’m trying to create multiple LinkButtons and wire then to a single event handler on the server. The link buttons render fine but when I check the rendered html theres no __doPostBack;
Here is my code:
LinkButton lb = new LinkButton();
lb.ID = "index" + loopIndex;
lb.Text = "click me";
lb.Click += new EventHandler(lb_Click);
lb.RenderControl(writer);
and the event handler ofcourse:
void lb_Click(object sender, EventArgs e)
{
}
Take into account that this is in PageLoad and inside a loop.
I think the problem is in the
lb.RenderControl(writer);and if you useform1.Controls.Add(lb);it will work.Reason: Since you are Rendering your control as a HTML Writer and HTML is added in the output and no event handler work!!