HighTechTalks DotNet Forums  

How to access controls

ASP.net Building Controls microsoft.public.dotnet.framework.aspnet.buildingcontrols


Discuss How to access controls in the ASP.net Building Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default How to access controls - 09-25-2003 , 01:29 PM






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

Reply With Quote
  #2  
Old   
John Saunders
 
Posts: n/a

Default Re: How to access controls - 09-25-2003 , 02:45 PM






"Skeeve" <google (AT) brasch (DOT) info> wrote

Quote:
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!
--
John Saunders
Internet Engineer
john.saunders (AT) surfcontrol (DOT) com




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.