Accessing Objects properties in User Control

T

tshad

I have a User Control with 4 Textboxes.

I want to be able to access the properties (.text, .visible, .enable etc)
directly from outside the Controls as the normal properties (.text, .visible
etc).

For example: at the moment I need to create a new property for each TextBox
since I can't figure out how to set up "text" as a property.

*********************************************
<Script Runat="Server">

Public Property Street As String
Get
Return txtStreet.Text
End Get
Set
txtStreet.Text = Value
End Set
End Property

Public Property City As String
Get
Return txtCity.Text
End Get
Set
txtCity.Text = Value
End Set
End Property

Public Property State As String
Get
Return txtState.Text
End Get
Set
txtState.Text = Value
End Set
End Property

Public Property ZIP As String
Get
Return txtZIP.Text
End Get
Set
txtZIP.Text = Value
End Set
End Property

</Script>

<p>Street Address:
<br>
<asp:TextBox
ID="txtStreet"
Runat="Server" />

<p>City:
<br>
<asp:TextBox
ID="txtCity"
Runat="Server" />

<p>State:
<br>
<asp:TextBox
ID="txtState"
Runat="Server" />

<p>ZIP:
<br>
<asp:TextBox
ID="txtZIP"
Runat="Server" />
*********************************************
In my .aspx file I may have the following:

<SuperCompany:Address
ID="ctlBillingAddress"
Runat="Server" />

I need to do:

ctlBillingAddress.Street = "xxx"

I understand that I can't do ctlBillingAddress.text as there would be no way
to know which textbox you are referring to.

I am curious if there is a better way to set this up with multiple objects
in my controls?

Thanks,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top