473,769 Members | 4,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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?
Nov 18 '05 #1
3 7143
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" <x@y.zzz> wrote in message
news:41******** **************@ news.song.fi...
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?

Nov 18 '05 #2
Hi,

UserControl.Pag e 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.P age, PAGE1).UC2 gives
you access to UC2.

HTH.

"qwerty" <x@y.zzz> wrote in message
news:41******** **************@ news.song.fi...
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?
Nov 18 '05 #3
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 <x@y.zzz> 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?


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4753
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
2
3024
by: paul meaney | last post by:
All, myself and another developer have been staring blankly at a screen for the past 48 hours and are wondering just what stunningly obvious thing we are missing. We are trying to load up 2 or more user controls dynamically by adding to a placeholder defined in page_load. I've included the sample code for how we are accessing one. The user controls are not rocket science - just a few text boxes with public accessor properties. We've...
2
2357
by: Jon Hyland | last post by:
This might be a dumb question, but what is the best way for one instance of a user control to access properties of an instance of another user control? For example, let's say I have an instance of UserControlA (ucA1) and an instance of UserControlB (ucB1) on a particular ASP.NET page. UserControlA has a string property called StringA that gets generated from a DB call in it's Page_Load event. I want UserControlB to be able to access...
5
3052
by: djscratchnsniffing | last post by:
i know you can access an ascx's properties/methods from an aspx file. Let's say you have an aspx file with two code-behind files(ascx files). Can you access one of the ascx file's properties/methods from the other ascx file?
2
1881
by: Sandy | last post by:
Hello - I have a registration page that could be altered slightly for different kinds of registrations if I was able to access the show/hide, enable/disable features from a page where people select the type of registration they would like. They select it with a radiobuttonlist, click submit and then are taken to the registration page. I am trying to avoid having a couple of different registration pages. How do I access the...
5
7672
by: Steve Richter | last post by:
In my user control I want to read the ViewState dictionary of the Parent control. But this sensible idea is not permitted by the compiler: Compiler Error Message: CS1540: Cannot access protected member 'System.Web.UI.Control.ViewState' via a qualifier of type 'System.Web.UI.Control'; the qualifier must be of type 'ASP.ItemOrderGrid' (or derived from it) Source Error:
2
1980
by: N. Demos | last post by:
I have a user control with code behind of which two instances are created/declared in my aspx page. The aspx page has code behind also, as I need to access methods of the usercontrols on page submit. I've read several post here and articles on the web on this topic. What little I have learned from them is that you have to pre-compile the usercontrol in order to access it in the aspx code behind. I did this, compiling the usercontrol...
2
10103
by: kumarpappu | last post by:
hello - I am newbie in winforms and c#. i have a mainform.cs and it has 2 user controls - leftView and rightView. In leftView.cs i am instantiating a new clientLeftView(another user control) and also the clientRightView(another user control) Now clientLeftView has a lstClient - list box.
7
2299
by: Andy B | last post by:
I have a class I am creating for data access. I need to access controls from inside the class that are on a particular page. How do I do this? or is creating an instance of the page class and using FindControl the only way to do it?
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.