UserControl awareness of calling page

  • Thread starter Thread starter MattB
  • Start date Start date
M

MattB

I have a UserControl that I use as a page header for my app. I want it to
vary depending on what page it's being called by. In the CodeBehind, how to
I refer to the calling page? Thanks!
 
MattB said:
I have a UserControl that I use as a page header for my app. I want
it to vary depending on what page it's being called by. In the
CodeBehind, how to I refer to the calling page? Thanks!

Oh, and this is vb.net in the codebehind, BTW.

Matt
 
Page p = this.Page;

You can create a base class or interface for all your pages, so that you
have a uniformed way to knowing what to be shown in the header.
 
Hi,

via the Page property of the user control. Just cast the Page property to
the code-behind type of the Page (if what you are accessing is declared
there) and off you go. Just note that this of course limits bit the
reusability of the user control as it needs to know on what page it is
used(when you are casting). If you don't need to get anything from Page's
code-behind type, you can just use the Page property (it is of type
System.Web.UI.Page) and then it, of course, does not limit the reusability.
 
Back
Top