• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

How do I inherit from Site.Master?

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
newbieweb
Asked:
newbieweb
  • 5
  • 2
3 Solutions
 
newbiewebSr. Software EngineerAuthor Commented:
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
 
newbiewebSr. Software EngineerAuthor Commented:
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
 
käµfm³d 👽Commented:
>>  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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
newbiewebSr. Software EngineerAuthor Commented:
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
 
Todd GerbertIT ConsultantCommented:
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
 
käµfm³d 👽Commented:
>>  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
 
newbiewebSr. Software EngineerAuthor Commented:
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
 
newbiewebSr. Software EngineerAuthor Commented:
I see tgerbert's answer should have tipped me off that you can only reference the Master page's properties.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now