How to access: a page from a User control, and another User controlfrom another one?

Discussion in 'ASP .Net' started by qwerty, Sep 30, 2004.

  1. qwerty

    qwerty Guest

    I have two User controls in a page.
    Them ID-propertys are example UC1 and UC2.

    In code behind file they are declared:
    Public UC1 As UC1
    Public UC1 As UC1

    From the page I can call them with their name (UC1 and UC2) and access
    their public propertys and functions.

    How can I access the page from a user control?
    How can I access another user control from another one?
     
    qwerty, Sep 30, 2004
    #1
    1. Advertising

  2. qwerty

    Karl Seguin Guest

    Re: How to access: a page from a User control, and another User control from another one?

    Each user control has a Page property, which gives it access to the page.
    In order to access those properties, you need to have it strongly-typed to
    the class of your page (for example, let's say WebForm1):

    dim otherControl as UC1 = ctype(Page, WebForm1).UC1

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "qwerty" <> wrote in message
    news:415bd7fd$0$3665$...
    > I have two User controls in a page.
    > Them ID-propertys are example UC1 and UC2.
    >
    > In code behind file they are declared:
    > Public UC1 As UC1
    > Public UC1 As UC1
    >
    > From the page I can call them with their name (UC1 and UC2) and access
    > their public propertys and functions.
    >
    > How can I access the page from a user control?
    > How can I access another user control from another one?
     
    Karl Seguin, Sep 30, 2004
    #2
    1. Advertising

  3. qwerty

    Shiva Guest

    Re: How to access: a page from a User control, and another User control from another one?

    Hi,

    UserControl.Page property gives you the reference to the containing page.

    One way to access an user control from another (both on the same page) is to
    use the page-usercontrol hierarchy itself. If for example PAGE1 contains UC1
    and UC2 (both are public), from UC1, DirectCast(Me.Page, PAGE1).UC2 gives
    you access to UC2.

    HTH.

    "qwerty" <> wrote in message
    news:415bd7fd$0$3665$...
    I have two User controls in a page.
    Them ID-propertys are example UC1 and UC2.

    In code behind file they are declared:
    Public UC1 As UC1
    Public UC1 As UC1

    From the page I can call them with their name (UC1 and UC2) and access
    their public propertys and functions.

    How can I access the page from a user control?
    How can I access another user control from another one?
     
    Shiva, Sep 30, 2004
    #3
  4. qwerty

    Scott Allen Guest

    Re: How to access: a page from a User control, and another User control from another one?

    A user control has a Page property you can use to get to the Page
    containing the control.

    WebForm1 form1 = (WebForm1)this.Page;

    If the page then exposes the user controls as public properties or as
    public fields (as you have done, it appears), you can reach them
    through the page reference:

    UC2 uc2 = form1.UC2

    or

    UC2 uc2 = ((WebForm1)this.Page).UC2;

    HTH,

    --
    Scott
    http://www.OdeToCode.com/

    On Thu, 30 Sep 2004 12:55:06 +0300, qwerty <> wrote:

    >I have two User controls in a page.
    >Them ID-propertys are example UC1 and UC2.
    >
    >In code behind file they are declared:
    > Public UC1 As UC1
    > Public UC1 As UC1
    >
    > From the page I can call them with their name (UC1 and UC2) and access
    >their public propertys and functions.
    >
    >How can I access the page from a user control?
    >How can I access another user control from another one?
     
    Scott Allen, Sep 30, 2004
    #4
    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. Reny J Joseph Thuthikattu
    Replies:
    1
    Views:
    562
    =?Utf-8?B?UHJha2FzaC5ORVQ=?=
    Dec 30, 2004
  2. =?Utf-8?B?REo=?=
    Replies:
    2
    Views:
    476
    =?Utf-8?B?REo=?=
    Dec 1, 2005
  3. loveNUNO
    Replies:
    2
    Views:
    926
    loveNUNO
    Nov 20, 2003
  4. Ben
    Replies:
    9
    Views:
    1,188
    John Timney \(MVP\)
    Jun 8, 2006
  5. Robert Cohen
    Replies:
    3
    Views:
    279
    Andrew Durstewitz
    Jul 15, 2003
Loading...

Share This Page