Accessing Other User Controls and Parents From User Control

Accessing Other User Controls and Parents From User Control

Post by Phil » Fri, 08 Apr 2005 14:30:33

Hi All,

I have a user control hierachy as follows:

- Main Page
   |--- User Control 1
   |       |--- User Control 1.1
   |       |--- User Control 1.2
   |--- User Control 2

My questions are:

1. How would i invoke a method in User Control 2 from User Control 1...
i know this probably doesn't make sense to do this but i would be
interested to know how anyway.

2. How would i reference an attribute/method in Main Page from any of
the User Controls?

3. How would i get the name of the Main Page from User Control 1 so
that i could dynamically build a URL... for example... in User Control
1, i want to create the following URL:<main page>?SomeId1=1&SomeId2=2

...obviously if User Control 1 is being called from a number of
different places <main page> is going to be different each time, so how
do i get that value?

Any help would be much appreciated,



Accessing Other User Controls and Parents From User Control

Post by jcves » Fri, 08 Apr 2005 20:52:54

(1) to get reference to MainPage from any of the usercontrols, use thje
Page property of the UserControl
(2) To refer to UserControl 1 from UserControl 2, you would access the
Controls property of the Main Page (Note - I believe you can see UC-1
and UC-2 in the Controls property, but I don't believe you can see
UC-1.1 or UC-2.2 ... I don't recall there being a "All" collection like
there is in DOM)
(3) To get the URL, use MyUserControl.Page.Request.ApplicationPath
(which gets you to the current application root virtual path)

Hope that helps - Joe.


Accessing Other User Controls and Parents From User Control

Post by jcves » Fri, 08 Apr 2005 21:05:35

to locate UC-2 from UC-1, assuming you know the ID of UC-2 :

private function FindUC2(UC2ID as string) as system.web.ui.usercontrol
dim ctrl as control
dim pg as =
for each ctrl in pg
    if ctrl.ID=UC2ID then return ctype(ctrl,system.web.ui.usercontrol)
return nothing
end function

Also, you can use the ResolveUrl method of the Page to  convert a
relative path (which you're likely to have) into an absolute virtual
path that can be given to a browser.



1. Accessing parent page's controls from user control

Is it possible for a user control to access the controls,
or at least perhaps a public/protected variable, on its
containing page?  I've gotten close.

Here's the scenario:

The web form is default.aspx
The user control is footer.ascx
default.aspx has a HtmlTableCell server control with
footer.ascx has a HtmlTableCell server control with

     I am looking to bind the Visible property of the
FooterLeftPane in footer.ascx to the Visible property of
the LeftPane in default.ascx (I programatically set the
LeftPane's Visible property in default.aspx and would
like it to cascade down to the Visible property for
FooterLeftPane in footer.ascx).

     In footer.ascx I am able to access Default.aspx in
the immediate window (in a debug session) using Page.  I
found a collection Page.Controls which it would seem
would hold the LeftPane control.  I assume I could use
Visible='<%# Page.[something] %>' in footer.ascx.  Is
this possible?  Any help would be appreciated!!

2. Password Sync Using Cisco LEAP

3. Access user control property in same user control .ascx code

4. XBOX rules. period.

5. Accessing Parent Page from web user control

6. Wireless Phone/ Palm Pilot

7. Access properties of parent page from user control

8. Content disappearing in RamDisk.

9. How can I access a textbox in user control from parent aspx page?

10. Compiled user controls not in my user controls toolbox...

11. How to control the focus as the user tabs into a user control?

12. Calling an user control from another user control

13. web user control within a web user control