Joel wrote:
> All web controls have a Page property. Just cast it to your derived type.
>
While this is definitely true, it's rarely a good idea to have the User
Control reference up to its parent container in this manner. Ideally,
User Controls should be agnostic about their container. This would
allow them to be plugged in and out of various pages without having to
muck with the code. By tying the UC to its parent, you destroy any
hopes at encapsulation and reusability. (Assuming that the UC is
accessing properties/methods of the parent container that are not
inherent to the Page class.)
If it is essential that the UC interacts with the parent page, a better
approach would be to use an interface or delegates. (Again, assuming
that the UC is accessing something other than a property/method already
outlaid in the Page class...)
> "Jenda Krynicky" <> wrote in message
> news:...
>
>>Sorry I'm probably missing something basic, but can't find it in the docs.
>>
>>Is it possible to access the public properties of the page containing the
>>UserControl from within the control? Without having to set the link up
>
> from
>
>>within the code of the page of course.
>>
>>Most of my pages inherit not from System.Web.UI.Page, but from my own
>
> class.
>
>>The class has a Public property, an object containing info about the
>>currently logged in user. Some of the pages use a UserControl I made. The
>>control also needs access to the object (or needs to create its own based
>
> on
>
>>the info in Context.User.Identity).
>>
>>I know I could add a public property "login" to the control and set it to
>>the created object from within the initialization code of the pages, I
>
> know
>
>>I could do it by just inheriting another template page from the one I
>>already have and inherit the pages that use this UserControl from the new
>>template, but I'd rather not. I think the control must have a reference to
>>its container already.
--
Scott Mitchell
http://www.4GuysFromRolla.com
* When you think ASP.NET, think 4GuysFromRolla.com!