Accessing values of one customer Control from another custom control

Discussion in 'ASP .Net Web Controls' started by Suresh Kumar, Nov 3, 2003.

  1. Suresh Kumar

    Suresh Kumar Guest

    Hi All,
    I am a newbie in creating ASP.NET custom controls. I have created one custom
    control say X.ascx for getting the location of the user like Country, State,
    and City. And I have created another control Y.ASCX which has X.ascx control
    also. The problem is how do I access the controls on X.ascx fromY.ascx
    control.

    Can anyone guide me on this???

    Thanks for the help.
    Suresh
     
    Suresh Kumar, Nov 3, 2003
    #1
    1. Advertising

  2. "Suresh Kumar" <> wrote in message
    news:...
    > Hi All,
    > I am a newbie in creating ASP.NET custom controls. I have created one

    custom
    > control say X.ascx for getting the location of the user like Country,

    State,
    > and City. And I have created another control Y.ASCX which has X.ascx

    control
    > also. The problem is how do I access the controls on X.ascx fromY.ascx
    > control.



    You don't.

    ASP.NET is object oriented. Among other things this means that you shouldn't
    have Y.ascx (which is a User Control, not a Custom Control) poking around in
    the guts of X.ascx. What happens if X.ascx decides to change what controls
    it uses?

    Instead, you should create public properties in X.ascx which return the
    values which other controls (including Y.ascx) might be interested in. For
    instance:

    X.ascx:

    ....
    <asp:TextBox runat="server" id="txtCountry" />
    ....
    X.ascx.cs:
    public string Country
    {
    get {return txtCountry.Text;}
    set {txtCountry.Text = value;}
    }

    Y.ascx:
    ....
    <uc1:X runat="server" id="X1"></uc1:X>
    ....
    Y.ascx.cs:
    ....
    // you can now access X1.Country

    --
    John
     
    John Saunders, Nov 4, 2003
    #2
    1. Advertising

  3. Suresh Kumar

    Suresh Kumar Guest

    Hi John,
    Thanks for the reply. I have created the public properties in X.ascx control
    but how do I access it in Y.ascx?
    Can you please paste some example here?
    thanks
    Suresh
    "John Saunders" <john.saunders at surfcontrol.com> wrote in message
    news:...
    > "Suresh Kumar" <> wrote in message
    > news:...
    > > Hi All,
    > > I am a newbie in creating ASP.NET custom controls. I have created one

    > custom
    > > control say X.ascx for getting the location of the user like Country,

    > State,
    > > and City. And I have created another control Y.ASCX which has X.ascx

    > control
    > > also. The problem is how do I access the controls on X.ascx fromY.ascx
    > > control.

    >
    >
    > You don't.
    >
    > ASP.NET is object oriented. Among other things this means that you

    shouldn't
    > have Y.ascx (which is a User Control, not a Custom Control) poking around

    in
    > the guts of X.ascx. What happens if X.ascx decides to change what controls
    > it uses?
    >
    > Instead, you should create public properties in X.ascx which return the
    > values which other controls (including Y.ascx) might be interested in. For
    > instance:
    >
    > X.ascx:
    >
    > ...
    > <asp:TextBox runat="server" id="txtCountry" />
    > ...
    > X.ascx.cs:
    > public string Country
    > {
    > get {return txtCountry.Text;}
    > set {txtCountry.Text = value;}
    > }
    >
    > Y.ascx:
    > ...
    > <uc1:X runat="server" id="X1"></uc1:X>
    > ...
    > Y.ascx.cs:
    > ...
    > // you can now access X1.Country
    >
    > --
    > John
    >
    >
     
    Suresh Kumar, Nov 4, 2003
    #3
  4. "Suresh Kumar" <> wrote in message
    news:#...
    > Hi John,
    > Thanks for the reply. I have created the public properties in X.ascx

    control
    > but how do I access it in Y.ascx?
    > Can you please paste some example here?
    > thanks


    Suresh, I gave an example.
    > > Y.ascx:
    > > ...
    > > <uc1:X runat="server" id="X1"></uc1:X>
    > > ...
    > > Y.ascx.cs:
    > > ...
    > > // you can now access X1.Country


    --
    John


    > Suresh
    > "John Saunders" <john.saunders at surfcontrol.com> wrote in message
    > news:...
    > > "Suresh Kumar" <> wrote in message
    > > news:...
    > > > Hi All,
    > > > I am a newbie in creating ASP.NET custom controls. I have created one

    > > custom
    > > > control say X.ascx for getting the location of the user like Country,

    > > State,
    > > > and City. And I have created another control Y.ASCX which has X.ascx

    > > control
    > > > also. The problem is how do I access the controls on X.ascx fromY.ascx
    > > > control.

    > >
    > >
    > > You don't.
    > >
    > > ASP.NET is object oriented. Among other things this means that you

    > shouldn't
    > > have Y.ascx (which is a User Control, not a Custom Control) poking

    around
    > in
    > > the guts of X.ascx. What happens if X.ascx decides to change what

    controls
    > > it uses?
    > >
    > > Instead, you should create public properties in X.ascx which return the
    > > values which other controls (including Y.ascx) might be interested in.

    For
    > > instance:
    > >
    > > X.ascx:
    > >
    > > ...
    > > <asp:TextBox runat="server" id="txtCountry" />
    > > ...
    > > X.ascx.cs:
    > > public string Country
    > > {
    > > get {return txtCountry.Text;}
    > > set {txtCountry.Text = value;}
    > > }
    > >
    > > Y.ascx:
    > > ...
    > > <uc1:X runat="server" id="X1"></uc1:X>
    > > ...
    > > Y.ascx.cs:
    > > ...
    > > // you can now access X1.Country
    > >
    > > --
    > > John
    > >
    > >

    >
    >
     
    John Saunders, Nov 4, 2003
    #4
  5. Suresh Kumar

    Suresh Kumar Guest

    I am sorry. I didnt see it. Thanks for your help.

    Suresh
    "John Saunders" <john.saunders at surfcontrol.com> wrote in message
    news:...
    > "Suresh Kumar" <> wrote in message
    > news:#...
    > > Hi John,
    > > Thanks for the reply. I have created the public properties in X.ascx

    > control
    > > but how do I access it in Y.ascx?
    > > Can you please paste some example here?
    > > thanks

    >
    > Suresh, I gave an example.
    > > > Y.ascx:
    > > > ...
    > > > <uc1:X runat="server" id="X1"></uc1:X>
    > > > ...
    > > > Y.ascx.cs:
    > > > ...
    > > > // you can now access X1.Country

    >
    > --
    > John
    >
    >
    > > Suresh
    > > "John Saunders" <john.saunders at surfcontrol.com> wrote in message
    > > news:...
    > > > "Suresh Kumar" <> wrote in message
    > > > news:...
    > > > > Hi All,
    > > > > I am a newbie in creating ASP.NET custom controls. I have created

    one
    > > > custom
    > > > > control say X.ascx for getting the location of the user like

    Country,
    > > > State,
    > > > > and City. And I have created another control Y.ASCX which has X.ascx
    > > > control
    > > > > also. The problem is how do I access the controls on X.ascx

    fromY.ascx
    > > > > control.
    > > >
    > > >
    > > > You don't.
    > > >
    > > > ASP.NET is object oriented. Among other things this means that you

    > > shouldn't
    > > > have Y.ascx (which is a User Control, not a Custom Control) poking

    > around
    > > in
    > > > the guts of X.ascx. What happens if X.ascx decides to change what

    > controls
    > > > it uses?
    > > >
    > > > Instead, you should create public properties in X.ascx which return

    the
    > > > values which other controls (including Y.ascx) might be interested in.

    > For
    > > > instance:
    > > >
    > > > X.ascx:
    > > >
    > > > ...
    > > > <asp:TextBox runat="server" id="txtCountry" />
    > > > ...
    > > > X.ascx.cs:
    > > > public string Country
    > > > {
    > > > get {return txtCountry.Text;}
    > > > set {txtCountry.Text = value;}
    > > > }
    > > >
    > > > Y.ascx:
    > > > ...
    > > > <uc1:X runat="server" id="X1"></uc1:X>
    > > > ...
    > > > Y.ascx.cs:
    > > > ...
    > > > // you can now access X1.Country
    > > >
    > > > --
    > > > John
    > > >
    > > >

    > >
    > >

    >
    >
     
    Suresh Kumar, Nov 4, 2003
    #5
    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. Benny Ng
    Replies:
    1
    Views:
    541
    bruce barker
    Jan 4, 2007
  2. Madison
    Replies:
    0
    Views:
    323
    Madison
    Mar 23, 2009
  3. Matt Sokol
    Replies:
    2
    Views:
    390
    Theo Tillotson
    Aug 7, 2003
  4. Suresh Kumar

    Accessing values of one customer Control from another custom control

    Suresh Kumar, Nov 3, 2003, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    187
    Suresh Kumar
    Nov 4, 2003
  5. jason
    Replies:
    12
    Views:
    192
    jason
    Oct 10, 2003
Loading...

Share This Page