Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > How to access controls

Reply
Thread Tools

How to access controls

 
 
Skeeve
Guest
Posts: n/a
 
      09-25-2003
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
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      09-25-2003
"Skeeve" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Controls.Count, Controls.IsSynchronized, and Controls.SyncRoot Nathan Sokalski ASP .Net 4 09-05-2007 03:27 AM
Web Controls/User Controls - Access Modifier Mr Newbie ASP .Net 3 10-31-2005 04:01 PM
using javascript in User controls to access server controls of the user control Faizan Ahmed ASP .Net Building Controls 1 01-04-2005 04:09 PM
using javascript in User controls to access server controls of the user control Faizan Ahmed ASP .Net Web Controls 1 01-04-2005 04:09 PM



Advertisments