UserControl awareness of calling page

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!
 
M

MattB

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
 
G

Guogang

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

Teemu Keiski

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.
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top