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

access members in the Master page class

Bob
In ASP.NET 1.1, I have a base page for all my pages in an application. The
base page contains some common properties that every page needs, the code
behind file of every page looks like this:

public class Home : MyBasePage {
.....
}

and in it I can simply refer them as base.MyProperty (or just
this.MyProperty). This seems no longer possible in the ASP.NET 20 master
page, as the code behind file for the master page is only a partial class.
There's no way to inherit from a partial class in the code behind file:

public partial class Home : MyMasterPage { //This does not work

}

If I simply add a new page assigning it the master page, any HTML code is
inherited but the members defined in the master page code behind file are
not recognized. Any way to make this work?

Thanks
Bob
Apr 17 '06 #1
4 1622
Sure, you can call methods on the master page with no problem.
Here are the details:
http://SteveOrr.net/faq/PassDataToMaster.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Bob" <bo*******@yahoo.com> wrote in message
news:u4**************@TK2MSFTNGP02.phx.gbl...
In ASP.NET 1.1, I have a base page for all my pages in an application.
The base page contains some common properties that every page needs, the
code behind file of every page looks like this:

public class Home : MyBasePage {
....
}

and in it I can simply refer them as base.MyProperty (or just
this.MyProperty). This seems no longer possible in the ASP.NET 20 master
page, as the code behind file for the master page is only a partial class.
There's no way to inherit from a partial class in the code behind file:

public partial class Home : MyMasterPage { //This does not work

}

If I simply add a new page assigning it the master page, any HTML code is
inherited but the members defined in the master page code behind file are
not recognized. Any way to make this work?

Thanks
Bob

Apr 17 '06 #2
Add the master file reference to your page markup:
<%@ MasterType VirtualPath="~/Default.master" %>

Then your page will have access to the master properties through your
inherited page's Master property.

Trevor Braun
"Bob" <bo*******@yahoo.com> wrote in message
news:u4**************@TK2MSFTNGP02.phx.gbl...
In ASP.NET 1.1, I have a base page for all my pages in an application.
The base page contains some common properties that every page needs, the
code behind file of every page looks like this:

public class Home : MyBasePage {
....
}

and in it I can simply refer them as base.MyProperty (or just
this.MyProperty). This seems no longer possible in the ASP.NET 20 master
page, as the code behind file for the master page is only a partial class.
There's no way to inherit from a partial class in the code behind file:

public partial class Home : MyMasterPage { //This does not work

}

If I simply add a new page assigning it the master page, any HTML code is
inherited but the members defined in the master page code behind file are
not recognized. Any way to make this work?

Thanks
Bob

Apr 17 '06 #3
Bob
Thanks a lot Steve, That's what I'm looking for. Though the extra type
cast is a bit hassle. I hope Microsoft would improve on the master page
concept to make it a true inheritance in the future.
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:uw**************@TK2MSFTNGP05.phx.gbl...
Sure, you can call methods on the master page with no problem.
Here are the details:
http://SteveOrr.net/faq/PassDataToMaster.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Bob" <bo*******@yahoo.com> wrote in message
news:u4**************@TK2MSFTNGP02.phx.gbl...
In ASP.NET 1.1, I have a base page for all my pages in an application.
The base page contains some common properties that every page needs, the
code behind file of every page looks like this:

public class Home : MyBasePage {
....
}

and in it I can simply refer them as base.MyProperty (or just
this.MyProperty). This seems no longer possible in the ASP.NET 20 master
page, as the code behind file for the master page is only a partial
class. There's no way to inherit from a partial class in the code behind
file:

public partial class Home : MyMasterPage { //This does not work

}

If I simply add a new page assigning it the master page, any HTML code is
inherited but the members defined in the master page code behind file are
not recognized. Any way to make this work?

Thanks
Bob


Apr 17 '06 #4
Thus wrote Bob,
Thanks a lot Steve, That's what I'm looking for. Though the extra
type cast is a bit hassle. I hope Microsoft would improve on the
master page concept to make it a true inheritance in the future.


It seems Steve missed the fact that you can get typesafe access to your Master
Page by specifying a MasterType directive in the content page, e.g.
<%@ MasterType VirtualPath="~/MasterPage.master" %>

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Apr 19 '06 #5

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

Similar topics

2
by: Steve Franks | last post by:
I am trying to access strongly typed properties in a page's master page from the content page. I followed an article that describes how to do this, and it seems quite straight forward. However...
5
by: RedHair | last post by:
I have a ASP.NET 2.0 web page which inherits a customized base page class and have a master page, their relation is as below Customized base page class --> web page --> master page How to...
4
by: RedHair | last post by:
I have a base page class A which inherits System.Web.UI.Page class then a aspx page B inherits class A and have a master page C. There is a property D (a string variable) in the master page C. ...
3
by: Alex Maghen | last post by:
Hi. I'm a little confused about the code that resides in the code-behind of a MasterPage and the code that resides in the code-behind of the actual pages that USE that MasterPage. I'm noticing,...
3
by: ivanpais | last post by:
Hi, I have a Web User Control, Lets say "Foo.ascx", that contains a button "btnFoo". I have a Master Page "Bar.master", that has a label "lblBar". This label is exposed by a public property...
4
by: Boris Yeltsin | last post by:
OK, on my Master Page I have a control: <a id="hypTabAccount" href="#" runat="server">Account</a> Now, in the code-behind (Root.master.vb) I can refer to it simply thus: ...
14
by: lovecreatesbea... | last post by:
Could you tell me how many class members the C++ language synthesizes for a class type? Which members in a class aren't derived from parent classes? I have read the book The C++ Programming...
0
by: Matt | last post by:
I am trying to access a property that I have created inside a Master Page. However all instruction that I have found shows them accessing the property from a .aspx page not a .aspx.vb page. My...
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.