我正在动态创建对象并将它们插入到 html 表中,对象是标签或链接按钮,如果它们是链接按钮,我需要为点击事件订阅一个事件处理程序,但我正在努力寻找一种方法来实际上添加处理程序。到目前为止的代码是:
WebControl myControl;
if _createLabel)
{
myControl = new Label();
}
else
{
myControl = new LinkButton();
}
myControl.ID = "someID";
myControl.GetType().InvokeMember("Text", BindingFlags.SetProperty, null, myControl, new object[] { "some text" });
if (!_createLabel)
{
// somehow do myControl.Click += myControlHandler; here
}
最佳答案
以下将起作用:
LinkButton lnk = myControl as LinkButton;
if (lnk != null)
{
lnk.Click += myControlHandler;
}
关于c# - 我可以延迟绑定(bind)到 C# 中的事件处理程序吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/867948/