events for dynamically created buttons nested in custom control

K

Kasabaarde Sumta

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

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top