how to reference properties of parent Page in UserControl

J

John A Grandy

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.Parent.Parent,MyPage)
 
K

Karl Seguin

No, asp.net isn't built that way,the control class exposes a Page
property...

dim parentPage as MyPage = ctype(Page, MyPage)


Karl
 

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,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top