User Controls
I have a user control (ascx) called _CountryList.
This control binds to a dataSet read from XML that came from a webService (with caching) that provides a list of countries.
This user control is then used on every web form that needs a listbox of countries (eg: Customer Registration, etc.)
So far this is all working great....
QUESTION: How do I access the selected country from within the code behind a web form that has the user control embedded?
CODE SNIPPET: (why does this not work?)
================================================== ===
Public Class Register
Protected WithEvents Countries As System.Web.UI.UserControl
Private Sub RegisterBtn_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles RegisterBtn.Click
If Page.IsValid Then
'Get the Country
Dim lbCountry As ListBox = DirectCast(Countries.FindControl("lbCountry"), ListBox)
Dim Country As String = lbCountry.SelectedItem.Value
lbCountry = Nothing
End Sub
End Class
================================================== ===
By my reckoning Country should contain the selected value.
Instead I get: 'Object reference not set to an instance of an object'
Thoughts, anyone ???
|