Similar questions to this have been raised. The answers I have read seem to
imply that I have to inherit to a new class in order to accomplish my goal
which seems excessive. So here goes. The situation is that I have created a
custom control in CS which mimics a modal dialog frame on an ASP(.NET). The
custom control requires the assignnation of a table as a attribute. The
table and its contents are built dynamically in the ASP code-behind. The
table contains the face of the dialog – text, textbox, buttons, images, etc.
and is created to suit the needs of the moment.
The problem is that dynamically created buttons that are placed within cells
of that dynamically created table do not seem to raise an event from within
the custom control. On the same page, I am dynamically creating
LinkButtons, placing them in the header of a DataGrid and attaching them to
custom event. That works perfectly. Any suggestions would be appreciated.
I have tried from the code behind:
Protected WithEvents findbutton As System.Web.UI.WebControls.Button

Public Function GetFindModal() As Table
findbutton = New Button
findbutton.ID = "findbutton"
findbutton.Text = "Find"
findbutton.CommandName = "find"
findbutton.CommandArgument = "yo"
findbutton.Width = System.Web.UI.WebControls.Unit.Pixel(60)
AddHandler findbutton.Command, AddressOf findbutton_command
End Function

Private Sub findbutton_Command(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.CommandEventArgs) Handles findbutton.Command
xcpMessage = "aaarrrrrggh!!! This should display on page!"
End Sub
As well as raising an event in the custom control itself:
public delegate void Command(object sender, CommandEventArgs e);
public event Command CommandEvent;

public void RegisterControl(Control ctrl){
if(ctrl!=null){
if(ctrl.GetType()==System.Type.GetType("Button")){
((Button)ctrl).Command += new CommandEventHandler(DSTModal_Command);
}
ctrlList.Add(ctrl);
}
}

private void DSTModal_Command(object sender, CommandEventArgs e){
CommandEvent(sender, e);
}


--
Kasabaarde Sumta