I'm creating objects dynamically and inserting them into an html table, the objects are either labels or linkbuttons, if they are linkbuttons i need to subscribe an eventhandler to the click event, but I'm struggling to find a way to actually add the handler. The code so far is:
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
}
The following will work:
LinkButton lnk = myControl as LinkButton;
if (lnk != null)
{
lnk.Click += myControlHandler;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With