Solved

How do I inherit from Site.Master?

Posted on 2011-02-15
8
444 Views
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?

Thanks,
newbieweb
0
Comment
Question by:newbieweb
  • 5
  • 2
8 Comments
 

Author Comment

by:newbieweb
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...
0
 

Author Comment

by:newbieweb
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?

newbieweb

0
 
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.
0
 

Author Comment

by:newbieweb
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...
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 33

Accepted Solution

by:
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;

Response.Write(masterPage.SomePropertyOnMasterPage);

Open in new window

0
 
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?
0
 

Author Comment

by:newbieweb
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.

0
 

Author Closing Comment

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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Icons and Colors for Terms 3 24
Interview questions for support of a legacy ASP.NET site 4 39
Error in JQuery 5 39
designing in object programming 12 42
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now