CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML





Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 12/29/2006 4:07:08 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 5 Views: 14 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
6 Items, 1 Pages 1 |< << Go >> >|
plq1
Asp.Net User
Inheriting from a base class in child pages12/29/2006 4:07:08 PM

0/0

Hi Folks

I have a master page which inherits my own base class : "public class common", in common.vb, and the common class Inherits System.Web.UI.MasterPage. Common creates a couple of extra public props, variables etc which can be utilised from the master page.

Now thats working great. The extra properties and backend server connection in the common class are accessible from the master page and, with the help of the MasterType directive, are also accessible from the child aspx page.

But to make this even better I wanted to change each child page to be based on a "base class" so the server variables on the Master page are available without putting code on each child page. So I created a base class "public class commonpage", which inherits System.Web.UI.Page. BUT the problem is that this class does not recognise the additional props and variables exposed in the master page. What do I need to inherit to make the extra props and variabels in common.vb accessible to the child page ?

In essence I think I'm asking the same questions as : "what does the @mastertype directive do behind the scenes?"

 thanks

jasonlindo
Asp.Net User
Re: Inheriting from a base class in child pages12/29/2006 8:09:01 PM

0/0

The only real way to implement what you're talking about is creating properites as such on your custom Page class (please excuse the C# syntax, I can't write VB without intelisense)

public string MyStringProp
{
 get
 {
  MyCustomMaster objMaster = (MyCustomMaster)this.MasterPage;
  return objMaster.MyStringProp;
 }
}

Hope that helps.

 

plq1
Asp.Net User
Re: Inheriting from a base class in child pages1/2/2007 3:51:31 PM

0/0

Thanks for responding. I am researching further and will post back here if I find out more info on this.
JoeReynolds
Asp.Net User
Re: Inheriting from a base class in child pages1/12/2007 8:57:59 PM

0/0

Hi plq1. Question. After you have your base class inhetiting from MasterPage, how can a user control be placed on the master page in way so the user control has access to the variables in your base class? Seems like the Page class must be used in the inheritance in some way for controls, but I see no way to do so.
docluv
Asp.Net User
Re: Inheriting from a base class in child pages1/12/2007 9:09:43 PM

0/0

I just made a Blog post about this type of use, Handling Master Page Button Control on the Content Page. It sounds like you need to make your properties public on your master page class. Second you have to cast the reference to your master page explicitly:

VB 

    Dim cmp As CustomMasterPage = CType(Master, CustomMasterPage)

C# 

    CustomMasterPage cmp = ((CustomMasterPage)(Master));

Once you do this any of the public members in your master page class, either in your base master page class or the child class (the one in the actual code-behind) will be available.

 


Chris Love
JoeReynolds
Asp.Net User
Re: Inheriting from a base class in child pages1/13/2007 8:52:09 PM

0/0

Dim cmp As CustomMasterPage produces a CustomMasterPage not defined error.
6 Items, 1 Pages 1 |< << Go >> >|



Search This Site:


Meet Our Sponsors:



Other Resources:

designing inheriting entities - microsoft.public.sqlserver.server - Web ... ... NeoChunkIO: SceneEntityChunk Class Reference : Scene entity base chunk for all ... menu with child menuitems showing below parent? templating site navigation ...
Inheritance from a Base Class in Microsoft .NET ( 12 printed pages) Objectives. Overview of inheritance. Learn how to inherit from a base class ... in the base class to reduce the amount of work a child ...
Amazon.com: "base class": Key Phrase page ... Basic can inherit from a base class written in C#, or in COBOL for that matter. ... See all pages with references to "base class". Excerpt - from Front Matter: ...
InformIT: Making The Most Of Your Inheritance > Inheriting from a Class ... Web pages and Web services will inherit from preexisting classes in the ... in a derived class has access to the members inherited from its base class is ...
Class-based programming - Wikipedia, the free encyclopedia ... from a child class cannot become an object of parent class because a child class and a parent class inherit a person class but class-based languages mostly do ...
WPF: Inheriting from custom class instead of Window This is a symptom that you changed the base class in the XAML and forgot to change it in the ... xbap application with a Main Page and several pages in Frames. ...
Social class - Wikipedia, the free encyclopedia ... class structure, while influenced by the Chinese, was based on ... class descriptions in quotes below are lifted from the 5th edition, pages 284 and 285.[25] ...



 
All Times Are GMT