Accessing Objects properties in User Control

Discussion in 'ASP .Net' started by tshad, Aug 3, 2006.

  1. tshad

    tshad Guest

    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
     
    tshad, Aug 3, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Moe Sizlak
    Replies:
    4
    Views:
    413
    Moe Sizlak
    Jul 17, 2004
  2. Craig G
    Replies:
    3
    Views:
    731
    Craig G
    Nov 30, 2004
  3. David

    Accessing user control properties

    David, Apr 12, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    307
    David
    Apr 12, 2007
  4. Max2006
    Replies:
    2
    Views:
    516
    Max2006
    Jul 13, 2007
  5. Sumeet Mahajan

    User Control - Accessing Properties from the Container Page

    Sumeet Mahajan, Mar 2, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    123
    Sumeet Mahajan
    Mar 2, 2004
Loading...

Share This Page