Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using inheritance with nested master pages

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'."

like image 920
WhiskerBiscuit Avatar asked Apr 29 '26 16:04

WhiskerBiscuit


1 Answers

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.

like image 88
SLaks Avatar answered May 01 '26 06:05

SLaks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!