3

I'm a .NET newbie, but here is my question:

I have an application that makes use of Master Pages. I have a page that has a formview on it used to input address information. In the insertitemtemplate is a usercontrol that I am referencing. This usercontrol is a dropdownlist that lists countries. The usercontrol has public properties to get and set the selected value. The usercontrol is not databound, but static. The id of the usercontrol in the user control .ascx files is "DropDownListCountry". When I reference it on the formview in the page, the ID is "fvDropDownListCountry".

When I am executing the command to save the user input of the formview, I want to get the selected value that the user has indicated of which country they have selected. For the other input areas, which are text boxes, I am able to use the code such as:

Dim street1 As String = CType(myFrmView.FindControl("fvTextBoxStreet1"), TextBox).Text

Quite obviously, this approach doesn't work for a drop down list which is inside of the user control. I can't forexample use:

Dim country As String = TryCast(myFrmView.FindControl("fvDropDownListCountry"), DropDownList).SelectedValue

I've looked all around to try to find the answer on how to get the selected value from this user control, but being new at this, haven't found it yet. I have looked at functions to recursively examine a control for child controls, but haven't been able to make this work.

Any help would be appreciated

estebane97
  • 1,138
  • 2
  • 7
  • 25

1 Answers1

0

Where are you trying to get this value? An asp.net TextBox <input type=text /> automatically maintains state but this is not true of an asp.net DropDownList <select />

If you are attempting to access the DropDownList during PageInit, that value will not have been loaded yet as ViewState is not available. You need to either access it in PageLoad or as part of the SelectedIndexChanged event on the DropDownList.

FYI: Pretty sure that you can set the SelectedIndex or SelectedValue properties during PageInit but you cannot read that value.

andleer
  • 22,388
  • 8
  • 62
  • 82