473,396 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to reference properties of parent Page in UserControl

Let's say I have an .aspx Page instance derived from class "MyPage" (which
of course inherits from System.Web.UI.Page).

On the .aspx Page , I have "uc1", an instance of a UserControl dervived from
"MyUserControl".

uc1 is contained in a <td> in a <tr> in a <table> in a <td> in a <tr> of
another <table> ... or some other form of deep nesting.

In uc1 's code-behind I'd like to reference some properties of the parent
Page.

I tried this code:

Dim parentPage As MyPage

parentPage = CType(Parent,MyPage)

but this throws a "cast invalid" error.

The only solution that occurs to me seems a little absured ....

Is ASP.NET written so that you must climb up the page's HTML control
hierarchy in some manner ?

In other words, should I be using something like :

parentPage =
CType(Parent.Parent.Parent.Parent.Parent.Parent.Pa rent.Parent,MyPage)



Nov 19 '05 #1
1 4642
No, asp.net isn't built that way,the control class exposes a Page
property...

dim parentPage as MyPage = ctype(Page, MyPage)
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:uT**************@TK2MSFTNGP14.phx.gbl...
Let's say I have an .aspx Page instance derived from class "MyPage" (which
of course inherits from System.Web.UI.Page).

On the .aspx Page , I have "uc1", an instance of a UserControl dervived
from "MyUserControl".

uc1 is contained in a <td> in a <tr> in a <table> in a <td> in a <tr> of
another <table> ... or some other form of deep nesting.

In uc1 's code-behind I'd like to reference some properties of the parent
Page.

I tried this code:

Dim parentPage As MyPage

parentPage = CType(Parent,MyPage)

but this throws a "cast invalid" error.

The only solution that occurs to me seems a little absured ....

Is ASP.NET written so that you must climb up the page's HTML control
hierarchy in some manner ?

In other words, should I be using something like :

parentPage =
CType(Parent.Parent.Parent.Parent.Parent.Parent.Pa rent.Parent,MyPage)


Nov 19 '05 #2

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

Similar topics

4
by: Mark Friedman | last post by:
I can't seem to figure out how to get a reference to a UserControl in the code-behind for the page that contains the control. All the examples I've seen show how to pass property values from the...
1
by: Martine | last post by:
Hi there! I have a problem with programmatically adding user controls to my mobile webforms. If I load my usercontrol programmatically (in the Page_Load), the object is instantiated, I have...
4
by: John | last post by:
Hi, is it possible for a UserControl to get the Page name and querystring of its parent? e.g If a userControl is inside a page called "index.aspx?ID=66" how can a usercontrol print out this...
1
by: dik | last post by:
Hi how do i change a property of a webcontrol that is on a asp.net from the code of a usercontrol? In other words what is the way to refer to the page from this user object? ch Dik ...
7
by: Samuel | last post by:
Hi, I am building a page that makes use of user control as a templating technique. The following is that I have in mind and it is actually working: Root/ -- login.aspx -- login.aspx.vb --...
8
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing...
13
by: Michael | last post by:
I have setup a public variable in the Master Page "code-behind-file". Now I would like to set that value from the UserControl, but I can't seem to find a way to do this. Does anyone have any ideas?...
3
by: Mark Rae | last post by:
Hi, Just a general quickie on setting properties of user controls from the parent form. Let's say I have a user control called note.ascx which displays a datagrid. That datagrid is populated...
1
by: mAbZ | last post by:
I neeed to instantiate an UserControl in an aspx page like this: <MyNamespace:MyControl ID="ctrl1" runat="server" MyParent="<%# this %>" /> where "this" is the current aspx page and should be...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.