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

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.
 
C

Chris Jackson

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.
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top