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

Q

qwerty

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?
 
K

Karl Seguin

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
 
S

Shiva

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.

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?
 
S

Scott Allen

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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top