Dynamic eventhandler

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");
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top