Retrieving values in user control placed in placeholder ctrl

  • Thread starter Thread starter Guest
  • Start date Start date
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,
 
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?
 
Back
Top