events for dynamically created buttons nested in custom control

Discussion in 'ASP .Net Building Controls' started by Kasabaarde Sumta, Oct 29, 2004.

  1. 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
    Kasabaarde Sumta, Oct 29, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    3
    Views:
    491
    Mark Rae
    Jan 8, 2007
  2. Amoril
    Replies:
    5
    Views:
    498
    Amoril
    Feb 21, 2007
  3. Nathan Sokalski

    Handling Events For Dynamically Created Buttons

    Nathan Sokalski, Feb 25, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    351
    Nathan Sokalski
    Feb 26, 2008
  4. msimmons
    Replies:
    0
    Views:
    460
    msimmons
    Jul 16, 2009
  5. Nathan Sokalski

    Handling Events For Dynamically Created Buttons

    Nathan Sokalski, Feb 25, 2008, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    147
    Nathan Sokalski
    Feb 26, 2008
Loading...

Share This Page