By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,928 Members | 1,810 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,928 IT Pros & Developers. It's quick & easy.

Dynamic eventhandler

P: n/a
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");
}
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi

Try to use LinkButton instead of HtmlAnchor

"Jacob" <je*@dlg.dk> wrote in message
news:5b**************************@posting.google.c om...
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");
}

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.