Programmatically create buttons from user control

Discussion in 'ASP .Net Building Controls' started by Jonah Olsson, Dec 7, 2003.

  1. Jonah Olsson

    Jonah Olsson Guest

    Hello guys,

    I have an application which is built upon several user controls. That is, I
    have a default template (default.aspx) that I load a user control into
    (using placeholders in the template).

    Now, the template also contains a placeholder for buttons used by each user
    control. The current solution needs each user control to create its buttons,
    like;

    Dim button As New Button
    button.Text = "buttontext"
    button.CssClass = "button"
    button.ID = "button_id"

    CType(Page.FindControl("buttonHolder"),
    PlaceHolder).Controls.Add(button)

    AddHandler button.Click, AddressOf button_click

    But instead I would like a more sophisticated method to simplify this and
    reduce code. Maybe using classes? I would like to just call a function like;
    CreateButton(buttonTitle As String, buttonId As String, addOnClickHandler As
    String)

    This function would also create AddHandlers and all that I currently need to
    add within each user control "by hand".
    Since the button placeholder mostly contains more than one button for each
    user control, maybe CreateButton should add the button to a array and then
    add that one to the placeholder through another function?

    Has anyone any experience in this? I'm very thankful for any feedback or
    ideas..
    Thanks.

    Regards,
    Jonah Olsson
    Jonah Olsson, Dec 7, 2003
    #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. Jonah Olsson
    Replies:
    1
    Views:
    439
    Eric Veltman
    Dec 8, 2003
  2. Roger
    Replies:
    1
    Views:
    628
    GreggTB
    May 20, 2005
  3. Mad Scientist Jr
    Replies:
    0
    Views:
    635
    Mad Scientist Jr
    Mar 22, 2006
  4. Jonathan Wood

    User Control to Control Other User Control

    Jonathan Wood, Jan 24, 2010, in forum: ASP .Net
    Replies:
    4
    Views:
    541
    Jonathan Wood
    Feb 2, 2010
  5. Leon
    Replies:
    3
    Views:
    1,574
    S. Justin Gengo
    Feb 12, 2010
Loading...

Share This Page