How to access controls

S

Skeeve

I am creating controls dynamically (programmatically) in a loop that
is navigating through a XML DOM.
Once I (the user) submit the form and reloads the page (or with
AutoPostBack), how can I access the controls (i.e. DropDownBoxes) to
get the value?

Since the Dropdownboxes are created in a loop, they all have the same
name don't they? I have no idea at this point how I can access the
individual controls.

Code_Snippet:

Dim DropDownBox As New DropDownList()
DropDownBox.AutoPostBack = True
tCell.Controls.Add(DropDownBox)
datas = element.childNodes
For Each data In datas
DropDownBox_String = data.lastChild.xml & " - " &
data.attributes.item(0).nodeValue
DropDownBox.Items.Add(DropDownBox_String)
Next data

Thanks,
Torsten
 
J

John Saunders

Skeeve said:
I am creating controls dynamically (programmatically) in a loop that
is navigating through a XML DOM.
Once I (the user) submit the form and reloads the page (or with
AutoPostBack), how can I access the controls (i.e. DropDownBoxes) to
get the value?

Since the Dropdownboxes are created in a loop, they all have the same
name don't they? I have no idea at this point how I can access the
individual controls.

Code_Snippet:

Dim DropDownBox As New DropDownList()
DropDownBox.AutoPostBack = True
tCell.Controls.Add(DropDownBox)
datas = element.childNodes
For Each data In datas
DropDownBox_String = data.lastChild.xml & " - " &
data.attributes.item(0).nodeValue
DropDownBox.Items.Add(DropDownBox_String)
Next data

Torsten,

When you are adding a variable number of controls to the same container, and
they all have the same name, you want the container to implement the
INamingContainer interface. That way, when you set the ID property of one of
the added controls, the ClientID will be prefixed by the ID of the
containing control. Because DataGridItem, DataListItem and RepeaterItem all
implement this interface, controls you place in the templates of the
DataGrid, DataList or Repeater controls all have their ID's prefixed.

Now, if you needed to, you could create your own container which does this
by creating a NamingContainer control:

public class NamingContainer : PlaceHolder, INamingContainer
{
}

then:

Dim nc as New NamingContainer()
tCell.Controls.Add(nc)
Dim DropDownBox As New DropDownList()
DropDownBox.AutoPostBack = True
nc.Controls.Add(DropDownBox)
....

I haven't tried this myself, so please let me know if it works!
 

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,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top