dynamically adding controls question

D

djc

I have something like the following:
---------------------------------------------------

Dim btnAddUpdateDetail As New LinkButton()
btnAddUpdateDetail.Text = "Add/Update Issue Detail"
btnAddUpdateDetail.CommandName = "AddUpdateDetail"
AddHandler btnAddUpdateDetail.Command, AddressOf HandleActions
ActionsPanel.Controls.Add(btnAddUpdateDetail)

Dim BR1 As New Literal()
BR1.Text = "<br/>"
ActionsPanel.Controls.Add(BR1)

Dim btnChangeType As New LinkButton()
btnChangeType.Text = "Change this issue's type"
btnChangeType.CommandName = "ChangeIssueType"
AddHandler btnChangeType.Command, AddressOf HandleActions
ActionsPanel.Controls.Add(btnChangeType)

Dim BR2 As New Literal() BR2.Text = "<br/>"
ActionsPanel.Controls.Add(BR2)
-------------------------------------------------------

1) is there a better way to do this that would relieve me of having to
create a seperate variable for each Literal control that is used to insert a
<br/> tag? I am dynamically loading these buttons based on some criteria and
there could be up to 6 or 7 buttons needed based on like 10 different
scenarios. The above example is just a small snippet of the code. I am using
a SELECT CASE statment and each case may have code like the example with up
to 6 or 7 buttons to create, each with a <br/> after them. There must be a
better way.
 
B

bruce barker

you can use the same variable, or standard refactoring principles would tell
you to make a function that returns a literal <br> that you call. in fact,
the pattern may be to create the button and the br, just pass the container,
text, commandname and callback routine.

-- bruce (sqlwork.com)


| I have something like the following:
| ---------------------------------------------------
|
| Dim btnAddUpdateDetail As New LinkButton()
| btnAddUpdateDetail.Text = "Add/Update Issue Detail"
| btnAddUpdateDetail.CommandName = "AddUpdateDetail"
| AddHandler btnAddUpdateDetail.Command, AddressOf HandleActions
| ActionsPanel.Controls.Add(btnAddUpdateDetail)
|
| Dim BR1 As New Literal()
| BR1.Text = "<br/>"
| ActionsPanel.Controls.Add(BR1)
|
| Dim btnChangeType As New LinkButton()
| btnChangeType.Text = "Change this issue's type"
| btnChangeType.CommandName = "ChangeIssueType"
| AddHandler btnChangeType.Command, AddressOf HandleActions
| ActionsPanel.Controls.Add(btnChangeType)
|
| Dim BR2 As New Literal() BR2.Text = "<br/>"
| ActionsPanel.Controls.Add(BR2)
| -------------------------------------------------------
|
| 1) is there a better way to do this that would relieve me of having to
| create a seperate variable for each Literal control that is used to insert
a
| <br/> tag? I am dynamically loading these buttons based on some criteria
and
| there could be up to 6 or 7 buttons needed based on like 10 different
| scenarios. The above example is just a small snippet of the code. I am
using
| a SELECT CASE statment and each case may have code like the example with
up
| to 6 or 7 buttons to create, each with a <br/> after them. There must be a
| better way.
|
|
 
D

djc

I got an error when I tried to use the same variable name. I'll check it out
again and post the error back here. Thanks for the reply.
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top