How to reference an object in a user control from its parent page

Discussion in 'ASP .Net' started by moondaddy, Jun 7, 2004.

  1. moondaddy

    moondaddy Guest

    I have a page which has a user control called CheckOutStatusBar and it lives
    in a table call like this:

    <%@ Register TagPrefix="uc1" TagName="CheckoutStatusBar"
    Src="Navigation/CheckoutStatusBar.ascx" %>
    html.....
    <td>
    <uc1:checkoutstatusbar id="CheckoutStatusBar1"
    runat="server"></uc1:checkoutstatusbar>
    </td>



    I need to change the formating of a link button in CheckoutStatusBar.ascx
    from its parent page. How an I get a reference to it from the parent page?

    Thanks.


    --
    moondaddy, Jun 7, 2004
    #1
    1. Advertising

  2. All you do is put a declaration into the page:

    Protected WithEvents CheckoutStatusBar1
    As "ProjectName"."UserControlClassName"

    and then it becomes available to you in code.

    hope this helps

    >-----Original Message-----
    >I have a page which has a user control called

    CheckOutStatusBar and it lives
    >in a table call like this:
    >
    ><%@ Register TagPrefix="uc1" TagName="CheckoutStatusBar"
    >Src="Navigation/CheckoutStatusBar.ascx" %>
    >html.....
    ><td>
    > <uc1:checkoutstatusbar id="CheckoutStatusBar1"
    >runat="server"></uc1:checkoutstatusbar>
    ></td>
    >
    >
    >
    >I need to change the formating of a link button in

    CheckoutStatusBar.ascx
    >from its parent page. How an I get a reference to it

    from the parent page?
    >
    >Thanks.
    >
    >
    >--
    >
    >
    >
    >.
    >
    Sergey Poberezovskiy, Jun 7, 2004
    #2
    1. Advertising

  3. moondaddy

    Natty Gur Guest

    Hi,

    CheckoutStatusBar oCheckoutStatusBar1 =
    FindControl("CheckoutStatusBar1");

    but you need to expose public or internal function from your user
    control that will handle link formating change.

    Natty Gur[MVP]

    blog : http://weblogs.asp.net/ngur
    Mobile: +972-(0)58-888377


    *** Sent via Devdex http://www.devdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur, Jun 7, 2004
    #3
  4. moondaddy

    moondaddy Guest

    Thanks that was perfect.

    --

    "Sergey Poberezovskiy" <> wrote in
    message news:18f1001c44c4b$a2213540$...
    > All you do is put a declaration into the page:
    >
    > Protected WithEvents CheckoutStatusBar1
    > As "ProjectName"."UserControlClassName"
    >
    > and then it becomes available to you in code.
    >
    > hope this helps
    >
    > >-----Original Message-----
    > >I have a page which has a user control called

    > CheckOutStatusBar and it lives
    > >in a table call like this:
    > >
    > ><%@ Register TagPrefix="uc1" TagName="CheckoutStatusBar"
    > >Src="Navigation/CheckoutStatusBar.ascx" %>
    > >html.....
    > ><td>
    > > <uc1:checkoutstatusbar id="CheckoutStatusBar1"
    > >runat="server"></uc1:checkoutstatusbar>
    > ></td>
    > >
    > >
    > >
    > >I need to change the formating of a link button in

    > CheckoutStatusBar.ascx
    > >from its parent page. How an I get a reference to it

    > from the parent page?
    > >
    > >Thanks.
    > >
    > >
    > >--
    > >
    > >
    > >
    > >.
    > >
    moondaddy, Jun 7, 2004
    #4
  5. "moondaddy" <> wrote in message
    news:...
    > I have a page which has a user control called CheckOutStatusBar and it

    lives
    > in a table call like this:
    >
    > <%@ Register TagPrefix="uc1" TagName="CheckoutStatusBar"
    > Src="Navigation/CheckoutStatusBar.ascx" %>
    > html.....
    > <td>
    > <uc1:checkoutstatusbar id="CheckoutStatusBar1"
    > runat="server"></uc1:checkoutstatusbar>
    > </td>
    >
    >
    >
    > I need to change the formating of a link button in CheckoutStatusBar.ascx
    > from its parent page. How an I get a reference to it from the parent

    page?

    It's best if you treat user controls like class instances (which they are).
    This means that a user control shouldn't be exposing its link buttons to
    the outside world. Instead, the user control should expose a method or
    property which allows the link button formatting to change. For instance, in
    the user control:

    private bool _linkUnderlined = true;
    public bool LinkUnderlined
    {
    get {return _linkUnderlined;}
    set
    {
    _linkUnderlined = value;
    if (_linkUnderlined)
    {
    lnkLinkButton.Styles["text-decoration"] = "underlined";
    }
    else
    {
    lnkLinkButton.Styles["text-decoration"] = "none";
    }
    }
    }
    --
    John Saunders
    johnwsaundersiii at hotmail
    John Saunders, Jun 7, 2004
    #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. Apple
    Replies:
    3
    Views:
    300
    Apple
    Aug 1, 2005
  2. thunk
    Replies:
    1
    Views:
    307
    thunk
    Mar 30, 2010
  3. thunk
    Replies:
    0
    Views:
    472
    thunk
    Apr 1, 2010
  4. thunk
    Replies:
    14
    Views:
    614
    thunk
    Apr 3, 2010
  5. Replies:
    0
    Views:
    136
Loading...

Share This Page