Retrieving values in user control placed in placeholder ctrl

G

Guest

Hello All,

I have a user control which is composed of a label and a dropdownlist. In
my code I add the user control to a placeholder on the webform. Now I want
to be able to retrieve the selected value from the drop downlist when a user
clicks a button server control.

Here is the code that populates the user control and placeholder:

Dim UControl As AugmentedDropDownList =
CType(LoadControl("../UserControls/AugmentedDropDownList.ascx"),
AugmentedDropDownList)

UControl.PopulateDropDownList(Control.Attributes("name").Value, DropDownNode)

plcContent.Controls.Add(UControl)

The first parameter in the PopulateDropDownList method contains the caption
for the label. The DropDownNode is an XmlNode that has the values of the
dropdownlist along with the values for the individual ListItems.

I can not figure out how to retrieve the values from the DropDownList in the
User Control. If any of you have any ideas, please let me know what they are.

TIA,
 
P

Peter Rilling

Working with dynamic controls can be tricky. You need to make sure that the
controls are available and in the Controls collection before the posted data
is processed. That usually means initializing all dynamic controls in the
Init event so that the page looks exactly like it was when it was sent to
the browser. That way ASP.NET can locate the control whose posted data was
submitted.

Another way would be to access the posted data directly using the old
fashioned way of Page.Request.Form (or something like that).

Does this help?
 

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

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top