How do I inherit from Site.Master?

Posted on 2011-02-15
Last Modified: 2012-06-27
I have a public property defined in Site.Master.cs, and I have defined that page as the Master Page in the Edit.aspx page. How can I access that property from Edit.aspx.cs?

Question by:newbieweb
  • 5
  • 2

Author Comment

ID: 34897995
I guess I need to make the object inherit from Site, instead of System.Web.UI.Page: pretty obvious.

But please confirm this is okay. I see that I need to then add a property to get it to compile...

Author Comment

ID: 34898058
When I change the inheritance, something strange happens:

When I change this:
public partial class Edit : System.Web.UI.Page

to this:
public partial class Edit : Site

I get a compilation problem since the compiler can not find the Title property

Title = table.DisplayName;

But Site inherits from System.Web.UI.Page so I do not understand why it suddenly can not find that property.  Any ideas?


LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 200 total points
ID: 34898291
>>  But Site inherits from System.Web.UI.Page so I do not understand why it suddenly can not find that property.

Because if you look at the markup page, you will see that it inherits a base class as well. The markup for Site will be able to access the members  it defined (private, public, protected, etc), but Edit will only have access to those members Site defines as either public or protected, not private.
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.


Author Comment

ID: 34898326
That makes sense. BUT, Title is a Public property.

An object that inherits from Site should also have access to Title.  That's classic OOP, I thought...
LVL 33

Accepted Solution

Todd Gerbert earned 300 total points
ID: 34898466
You can reference Page.Master in Edit.aspx.cs to get a reference to Site.Master.cs.

YourMasterPageClass masterPage = this.Master as YourMasterPageClass;


Open in new window

LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 200 total points
ID: 34898805
>>  That's classic OOP, I thought...

It is. Without seeing the code, though, it's hard to diagnose the issue. Can you recreate an example?

Author Comment

ID: 34899153
I found the problem. While making a list of source code for you, I realized Site is a MasterPage, yet Edit was a Page.

I think I need to leave Site.Master.cs alone and add a new abstract Page that deals with permissions.


Author Closing Comment

ID: 34899174
I see tgerbert's answer should have tipped me off that you can only reference the Master page's properties.

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Iteration Help ( VB) 5 24
Tracing a live website down to the files which support it 2 25
ASP.NET (VB) return a record 2 37
Visual Studio npm 1 11
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question