Programmatically create buttons from user control

J

Jonah Olsson

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
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top