Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / September 2003

Tip: Looking for answers? Try searching our database.

How to access controls

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Skeeve - 25 Sep 2003 18:29 GMT
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
John Saunders - 25 Sep 2003 19:45 GMT
> I am creating controls dynamically (programmatically) in a loop that
> is navigating through a XML DOM.
[quoted text clipped - 17 lines]
>       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!
Signature

John Saunders
Internet Engineer
john.saunders@surfcontrol.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.