Dynamic eventhandler

  • Thread starter Thread starter Jacob
  • Start date Start date
J

Jacob

In the following code I'm making a list of links.
When you click a link I want an event to be raised. I have inserted
the Event-code in the bottom of this mail.

When I click a link a postback is made, but the method
lnkShowList_Click is ignored. What do I do wrong?


TableRow tblRow;
TableCell tblCell;
HtmlAnchor link;

foreach(DataRow row in ds.Tables[0].Rows)
{
tblRow = new TableRow();
tblCell = new TableCell();
link = new HtmlAnchor();
link.InnerText = row["CategoryName"].ToString();
link.ID = guidSubCategory;
link.ServerClick += new System.EventHandler(this.lnkShowList_Click);
tblCell.Controls.Add(link);
tblRow.Cells.Add(tblCell);
tblFaqList.Rows.Add(tblRow);
}




Event method:

private void lnkShowList_Click(object sender, EventArgs e)
{
Trace.Warn("test","Test");
}
 
Back
Top