By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,712 Members | 1,231 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,712 IT Pros & Developers. It's quick & easy.

Accessing Objects properties in User Control

P: n/a
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
Aug 3 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.