Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > events for dynamically created buttons nested in custom control

Reply
Thread Tools

events for dynamically created buttons nested in custom control

 
 
Kasabaarde Sumta
Guest
Posts: n/a
 
      10-29-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Handling Events For Dynamically Created Buttons Nathan Sokalski ASP .Net 2 02-26-2008 03:01 AM
Handling Events For Dynamically Created Buttons Nathan Sokalski ASP .Net Web Controls 2 02-26-2008 03:01 AM
trouble with click events on dynamically created link buttons Amoril ASP .Net 5 02-21-2007 04:12 AM
Handling events from dynamically created link buttons Mark ASP .Net 3 01-08-2007 06:17 PM
Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created) dickster ASP .Net Building Controls 0 12-08-2005 09:32 AM



Advertisments