PageClassName from UserControl

G

Guest

I am inside a usercontrol and would like to get a reference to the page that
user control is contained in. Here is my code:

MyPageClassName myPage = this.Page

What I cannot figure out is how I get the MyPageClassName part. For
instance, shouldn't it be the same as the class name specified in my Code
Behind?

I have a page named Default.aspx inside a folder named 'admin'. I am trying
admin_Default but does not work.

Thanks,

~ steve
 
A

Aru

Make sure you are using the namespace of _Default page like:

using MyProject;

And to access the page, you can do something like:

_Default myPage = (_Default) Page;

Hth,
Aru
 
S

Steven Cheng[MSFT]

Hi steve,

I think you are using ASP.NET 2.0, yes? If so, due to the new compilation
model of ASP.NET 2.0 web application, all the page classes (or usercontrol
class) are dynamically compiled at runtime. And as for the page's class
type, both the runtime page type(derived from codebehind page class) and
the codebehind page class are compiled and defined at runtime. So at
design-time, we can not directly reference that partial class type (unless
we use @Reference directive to reference that certain page or usercontrol's
file ). For your scenario, I think you can consider the following options:

1. Define an additional base page type, and let the page's codebehind
class derived from that base page type. e.g:

public partial class XXXPage : MyBasePageClass
{

Then, at runtime, you can cast the page to that base page class to access
any particular properties.

2.or you can also consider using interface to encapsulate some common
functions and let the codebehind page class implement that interface. And
at runtime, we cast the page instance to the instance type to access
specific data.

public partial class XXXPage : System.Web.UI.Page, ICustomIntf
{

Here is other web articles describing the ASP.NET 2.0 compilation/page
model:

http://msdn.microsoft.com/msdnmag/issues/06/01/ExtremeASPNET/

http://odetocode.com/Blogs/scott/archive/2005/06/30/1889.aspx


Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Top