PC Review


Reply
Thread Tools Rate Thread

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

 
 
qwerty
Guest
Posts: n/a
 
      30th Sep 2004
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?
 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      30th Sep 2004
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" <(E-Mail Removed)> wrote in message
news:415bd7fd$0$3665$(E-Mail Removed)...
> 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?



 
Reply With Quote
 
Shiva
Guest
Posts: n/a
 
      30th Sep 2004
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" <(E-Mail Removed)> wrote in message
news:415bd7fd$0$3665$(E-Mail Removed)...
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?


 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      30th Sep 2004
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 <(E-Mail Removed)> 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?


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access Page's local resource from user control schneider@rehm.de Microsoft ASP .NET 1 17th Apr 2007 12:27 PM
Access Methods on Page from user control =?Utf-8?B?Q29uZ2Vybw==?= Microsoft ASP .NET 1 16th May 2006 01:07 PM
ASP 2.0: How to access Master Page from Web User Control on Page? ivanpais@gmail.com Microsoft ASP .NET 3 15th May 2006 05:23 PM
How to access a parent page method while in a user control. Steve Kershaw Microsoft ASP .NET 1 7th Dec 2005 10:39 PM
access to page from user control Alex Wagner Microsoft ASP .NET 2 21st Apr 2004 02:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:40 PM.