I tried what you suggested, it didn't work or I didn't do something right. I tried another approach. I will try to describe my controls in detail:
In ctlCompanies.ascx.vb (ctlCompanies.ascx contains DDL which is DataBound to the DB table, displays CompanyName, value is CompanyID):
'declare variable to hold a selected value of DDL
Dim uxSelectedCompanyID As String
'when control loads, get the selected value of DDL on DataBound
Protected Sub uxCompaniesDDL_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxCompaniesDDL.DataBound
uxSelectedCompanyID = uxCompaniesDDL.SelectedValue
End Sub
'when user chooses a selection from DDL
Protected Sub uxCompaniesDDL_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxCompaniesDDL.SelectedIndexChanged
uxSelectedCompanyID = uxCompaniesDDL.SelectedValue
End Sub
'property to return DDL selected value
Public ReadOnly Property GetCompanyID() As String
Get
Return "-=value is -- " & uxSelectedCompanyID & " =-"
End Get
End Property
In ViewForms.ascx.vb (VieForms.ascx holds ctlCompanies.ascx, Label1, and uxShowResearchButton; when button is clicked it should get the selected CompanyID from ctlCompanies control and put it in the label (for now, after I get this part working I will need to pass it to the next form control to display related records):
Protected Sub uxShowResearchButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxShowResearchButton.Click
Dim objCompanyID As New ctlCompanies
Label1.Text = "This is the value from ctlCompanies control: " & objCompanyID.GetCompanyID()
End Sub
The uxSelectedCompanyID holds the value while in the ctlCompanies control, but when I call it from ViewForms control I'm getting empty string. Where am I loosing it?
Thanks,
Waldis