3

Summary of problem:

I would like to create a master page, and from that a nested master page, and finally from that a webform that inerhits from the nested master page.

The master page should have property Foo and the nested master page should have property Bar

Ideally I would like for the webform to have access to those inherited properties, however when I change my webform's code-behind class from System.Web.UI.Page to NestedMasterPage1 I'm getting an RTE saying that I need to extend class 'System.Web.UI.Page'.

I bet there is a better way of doing this, but so far I can't find one.

Thanks for reading!!!

Steps to reproduce: Create Site1.Master and from that page create NestedMasterPage1.master and from that create WebForm1.aspx.

On the codebehind for Site1.Master create public Property Foo

On the codebehind for NestedMasterPage1.master create Public Property Bar

Change the codebehind for NestedMasterPage1 to inherit from Site1 instead of System.Web.UI.MasterPage

Change the codebehind for Webform1.aspx, inheriting from NestedMasterPage1 instead of System.Web.UI.Page

Everything compliles, running gets the following error:

"Parser Error Message: 'WebApplication2.WebForm1' is not allowed here because it does not extend class 'System.Web.UI.Page'."

1 Answer 1

4

You can't do that; pages do not inherit their master pages.

Instead, you can cast the page's Master property to NestedMasterPage1 to access the master class.

Sign up to request clarification or add additional context in comments.

1 Comment

This one seems to trip everyone up the first time around, and without understanding the underlying implementation it can be a little counter-intuitive that the masterpage is a child of the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.