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 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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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.
...
|
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,...
|
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...
|
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:
...
|
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...
|
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...
|
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" %>...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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: 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...
| |