Object loaded in Page & UserControl... not sure if i"m doing this right...

  • Thread starter Thread starter AC
  • Start date Start date
A

AC

I have a page class that inherits the System.Web.UI.Page class. Essentially what it does is load a user profile from a session (if it isn't loaded, it loads it into the session) and exposes it via a public property. This works just fine.

I have user controls that require the profile as well and I was coding it to work in the same way (created a class that inherits the System.Web.UI.UserControl class. It does the exact same thing as the page class I created.

My question is I'm wondering if I'm doing more owrk than is necessary. Can the UserControl see the page object? If it can, what's the execution order (would the control execute before the page so the user control wouldn't have access to the profile)?

Thanks in advance.
 
A UserControl object exposes a Page attribute, which you can use to get a
reference to the hosting page. If you initialize your variable in your
OnInit event handler of your page, and then read it in your OnLoad event
handler of your control, you should be fine.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

I have a page class that inherits the System.Web.UI.Page class. Essentially
what it does is load a user profile from a session (if it isn't loaded, it
loads it into the session) and exposes it via a public property. This works
just fine.

I have user controls that require the profile as well and I was coding it to
work in the same way (created a class that inherits the
System.Web.UI.UserControl class. It does the exact same thing as the page
class I created.

My question is I'm wondering if I'm doing more owrk than is necessary. Can
the UserControl see the page object? If it can, what's the execution order
(would the control execute before the page so the user control wouldn't have
access to the profile)?

Thanks in advance.
 
Back
Top