473,326 Members | 2,090 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,326 software developers and data experts.

Get reference to Master Page type

PJ
How can I get a reference to the master page class? It is defined as a
partial class, but I cannot seem to type a variable to the name of the
partial class? The compiler continually shows "The type 'MyMaster' is not
defined."

I would like to reference the master page from a control, by casting the
Master property of the Page property to the type, but obviously I cannot do
this if I can't get a reference to the actual type.

Thanks,
~PJ

Jan 4 '06 #1
8 2345
Here's a code snipped from my app:

master_AppResMortApp master = (MasterType)this.Master;

Where "MasterType" is the type defined in the master page source:
public class MasterType : MasterPage {
"PJ" <pj******@hotmail.com> wrote in message news:Qq******************************@speakeasy.ne t...
How can I get a reference to the master page class? It is defined as a
partial class, but I cannot seem to type a variable to the name of the
partial class? The compiler continually shows "The type 'MyMaster' is not
defined."

I would like to reference the master page from a control, by casting the
Master property of the Page property to the type, but obviously I cannot do
this if I can't get a reference to the actual type.

Thanks,
~PJ


Jan 4 '06 #2
Look at this article from the MSDN:
http://msdn2.microsoft.com/en-us/library/c8y19k6h.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"PJ" wrote:
How can I get a reference to the master page class? It is defined as a
partial class, but I cannot seem to type a variable to the name of the
partial class? The compiler continually shows "The type 'MyMaster' is not
defined."

I would like to reference the master page from a control, by casting the
Master property of the Page property to the type, but obviously I cannot do
this if I can't get a reference to the actual type.

Thanks,
~PJ

Jan 4 '06 #3
Hi,

Could using @MasterType directive on that page solve the problem? Probably,
but it would also make you cast Page property to the type of the Page (so
that Master property is typed), which would seriously harm the reusability
of your control.

@MasterType
http://msdn2.microsoft.com/en-us/library/ms228274.aspx

So, any chance that what the control is actually looking for from the master
page, is actually delivered to it via property, so that it wouldn't be tied
to a specific master page or just a specific Page?

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"PJ" <pj******@hotmail.com> wrote in message
news:Qq******************************@speakeasy.ne t...
How can I get a reference to the master page class? It is defined as a
partial class, but I cannot seem to type a variable to the name of the
partial class? The compiler continually shows "The type 'MyMaster' is not
defined."

I would like to reference the master page from a control, by casting the
Master property of the Page property to the type, but obviously I cannot
do
this if I can't get a reference to the actual type.

Thanks,
~PJ

Jan 4 '06 #4
PJ
When you add a master page to an app it creates it as a partial class. Yours is not.

I am trying to get a reference to the master page type from the a class within the app_code directory. Apparently, none of the partial classes created by the aspx pages, master pages, and controls are available to classes in the app_code directory. asp.net does not let you add master pages to the app_code directory.

So it seems as if you must create a class that your master page will inherit from, which is perhaps what you have done? Also, implementing an interface is another option, which I have done.

Someone please correct me if I'm wrong or feel free to add to this.

~PJ
"Gabriel Magaña" <no*****@no-spam.com> wrote in message news:u1**************@TK2MSFTNGP14.phx.gbl...
Here's a code snipped from my app:

master_AppResMortApp master = (MasterType)this.Master;

Where "MasterType" is the type defined in the master page source:
public class MasterType : MasterPage {
"PJ" <pj******@hotmail.com> wrote in message news:Qq******************************@speakeasy.ne t...
How can I get a reference to the master page class? It is defined as a
partial class, but I cannot seem to type a variable to the name of the
partial class? The compiler continually shows "The type 'MyMaster' is not
defined."

I would like to reference the master page from a control, by casting the
Master property of the Page property to the type, but obviously I cannot do
this if I can't get a reference to the actual type.

Thanks,
~PJ


Jan 4 '06 #5
PJ
Yes, this works in pages that use the master pages, but not for user
controls. See above post.

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
Hi,

Could using @MasterType directive on that page solve the problem? Probably, but it would also make you cast Page property to the type of the Page (so
that Master property is typed), which would seriously harm the reusability
of your control.

@MasterType
http://msdn2.microsoft.com/en-us/library/ms228274.aspx

So, any chance that what the control is actually looking for from the master page, is actually delivered to it via property, so that it wouldn't be tied to a specific master page or just a specific Page?

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"PJ" <pj******@hotmail.com> wrote in message
news:Qq******************************@speakeasy.ne t...
How can I get a reference to the master page class? It is defined as a
partial class, but I cannot seem to type a variable to the name of the
partial class? The compiler continually shows "The type 'MyMaster' is not defined."

I would like to reference the master page from a control, by casting the
Master property of the Page property to the type, but obviously I cannot
do
this if I can't get a reference to the actual type.

Thanks,
~PJ


Jan 4 '06 #6
If you want a control to manipulate the layout of the pages in your
application then instead of attempting to directly access the masterpage
members why do not you program the control to raise events to be handled by
the webform that will contain the control. The webform can thereafter access
the controls and members of the master page and change them based on the
criteria that you passed through the eventargs. If you have any further
questions on how to create events and event arguments, let me know.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"PJ" wrote:
When you add a master page to an app it creates it as a partial class. Yours is not.

I am trying to get a reference to the master page type from the a class within the app_code directory. Apparently, none of the partial classes created by the aspx pages, master pages, and controls are available to classes in the app_code directory. asp.net does not let you add master pages to the app_code directory.

So it seems as if you must create a class that your master page will inherit from, which is perhaps what you have done? Also, implementing an interface is another option, which I have done.

Someone please correct me if I'm wrong or feel free to add to this.

~PJ
"Gabriel Magaña" <no*****@no-spam.com> wrote in message news:u1**************@TK2MSFTNGP14.phx.gbl...
Here's a code snipped from my app:

master_AppResMortApp master = (MasterType)this.Master;

Where "MasterType" is the type defined in the master page source:
public class MasterType : MasterPage {
"PJ" <pj******@hotmail.com> wrote in message news:Qq******************************@speakeasy.ne t...
> How can I get a reference to the master page class? It is defined as a
> partial class, but I cannot seem to type a variable to the name of the
> partial class? The compiler continually shows "The type 'MyMaster' is not
> defined."
>
> I would like to reference the master page from a control, by casting the
> Master property of the Page property to the type, but obviously I cannot do
> this if I can't get a reference to the actual type.
>
> Thanks,
> ~PJ
>
>
>

Jan 4 '06 #7
So it seems as if you must create a class that your master page will inherit from, which is perhaps what you >have done? Also, implementing an interface is another option, which I have done.


Yes this is the code I call from a page that uses a master page. Sorry if I misunderstood your question, I have never needed to tackle the same problem as you...
Jan 4 '06 #8
Note what I said about having properties on the control being set by the
page (or having events as was said), instead of trying to access the Page &
Master page from the control in a typed manner (plus that they indeed are
not available, since in VS2005 page codebehind are compiled last, unless you
add the base class of your page to app_code). It reduces reusability of your
control if you tie it to a specific (master) page.

Something like discussed here:
http://www.csharper.net/blog/accessi...p_net_2_0.aspx
http://odetocode.com/Blogs/scott/arc...9/12/2186.aspx
http://west-wind.com/weblog/posts/3016.aspx

Anyways, I'd think that the new Web Application project might give a
solution to this since it changes the VS2005 to have VS2003 type of model
(all pre-built into a single assembly, just as it is with VS2003)
http://webproject.scottgu.com

Specifically
http://webproject.scottgu.com/CSharp...odeBehind.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"PJ" <pj******@hotmail.com> wrote in message
news:9c********************@speakeasy.net...
Yes, this works in pages that use the master pages, but not for user
controls. See above post.

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
Hi,

Could using @MasterType directive on that page solve the problem?

Probably,
but it would also make you cast Page property to the type of the Page (so
that Master property is typed), which would seriously harm the
reusability
of your control.

@MasterType
http://msdn2.microsoft.com/en-us/library/ms228274.aspx

So, any chance that what the control is actually looking for from the

master
page, is actually delivered to it via property, so that it wouldn't be

tied
to a specific master page or just a specific Page?

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"PJ" <pj******@hotmail.com> wrote in message
news:Qq******************************@speakeasy.ne t...
> How can I get a reference to the master page class? It is defined as a
> partial class, but I cannot seem to type a variable to the name of the
> partial class? The compiler continually shows "The type 'MyMaster' is not > defined."
>
> I would like to reference the master page from a control, by casting
> the
> Master property of the Page property to the type, but obviously I
> cannot
> do
> this if I can't get a reference to the actual type.
>
> Thanks,
> ~PJ
>
>
>



Jan 4 '06 #9

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

Similar topics

0
by: Abraham Andres Luna | last post by:
i have a master page: <%@ Master Language="C#" %> <html> <head> <title>CRM - RDK Truck Sales & Service</title> </head> <body> <form runat="server"> <asp:contentplaceholder...
3
by: Mark Olbert | last post by:
I have some img tags on a master page which reference files in a top-level directory. They look like this: <img src="assets/test.gif" id="gnr" /> assets is a subdirectory of the website root. ...
0
by: John Holmes | last post by:
I have a website that consists of numerous ASP.NET applications (each referred to as a website in VS 2005) which I'd like to have share a master page. My directory structure on the website is like...
13
by: Michael | last post by:
I have setup a public variable in the Master Page "code-behind-file". Now I would like to set that value from the UserControl, but I can't seem to find a way to do this. Does anyone have any ideas?...
3
by: Managed Code | last post by:
I have a BasePage class that derives from System.Web.UI.Page. All of my content pages derive from this. The derived page classes use the following MasterType declaration that follows to reference...
1
by: Argirop | last post by:
In my web project I have a folder called "Controls". Into this folder there is an ascx control called "Sidemenu". The user control has a get-set public string proterty called "MenuType". The...
13
by: Dan Aldean | last post by:
Hi, I use ASP.NET 2.0 and I created a stylesheet, but I don't know how to make it visible to a web form "MyWebPage.aspx" that uses the master page. I put a reference to the css in the .master...
35
by: Chris | last post by:
Hi, I tried to create a class which must change the propety 'visible' of a <linktag in the masterpage into 'false' when the user is logged. But i get the error: "Object reference not set to an...
5
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys I'm trying to make my code as streamlined as possible, and add CSS file references dynamically when they are required, for example, if a page contains a webcontrol, then the related CSS...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.