tags:

views:

717

answers:

2

Hi,

I have a long form that the user has to fill out.

So I broke the form into logical units and created another user control for some elements (they will be resued elsewhere).

So say the form has these fields:

UserControl3.ascx

Username password email -- usercontrol2.ascx address -- usercontrol2.ascx city -- usercontrol2.ascx state -- usercontrol2.ascx

So now in the codebehidn of usercontrol3.ascx, how will I access the usercontrol2.ascx's fields so I can write to the db?

+1  A: 

if user control 3 contains user control 2, I would modify the code for user control 2 to expose public properties for the information that you need to retreive.

edit There are other ways of doing it, but the property route is the safest route, and avoids strong dependencies between the two controls.

Mitchel Sellers
A: 

Something like this works, but it is just not elegant:

Dim txtBox as TextBox = Ctype(parentControl.Controls(Index), System.Web.UI.Controls.TextBox)
stringVariable = txtBox.Text

The correct way to do it is to implement properties for your parentControl that access child's controls properties.

Public Property AddressField() as string
  Set(byval value as string)
    txtAddressField.Text = value
  End Set
  Get
    Return txtAddressField.Text
  End Get
End Property
vmarquez