473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PageClassName from UserControl

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
Apr 21 '06 #1
2 951
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

Apr 21 '06 #2
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/is...ExtremeASPNET/

http://odetocode.com/Blogs/scott/arc...6/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.)

Apr 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Veeneman | last post by:
Is there a simple way to pass drag-and-drop events to a child control in a UserControl? Here's an example: I have created a UserControl which contains a treeview and some text boxes. I want to...
8
by: Raed Sawalha | last post by:
Hi, I have a strange problem with a usercontrol on a page. The usercontrol dispalyes three categories (From a database) when the user clicks a category they see all the products in a shop for...
2
by: Eric Maia | last post by:
I have two UserControls I am using in a form. These are each also used separately in two other forms. The structure is essentially this: CourseUserControl.ascx - select or enter a course...
2
by: Sascha | last post by:
Hi there, I searched carefully through the web before finally deciding to post this message, because I could not find a solution for my problem. Hopefully someone will have a hint or explanation...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
9
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it...
6
by: MeowCow | last post by:
I have created a UserControl that encapsulates a third party data grid. My goal was to create my own DataSource and DataMember properties that forward the binding to the third party grid, then use...
10
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.