简体   繁体   中英

Nested MasterPages

Currently I have two MasterPages. One is the child of the other.

Parent:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Parent.master.cs" Inherits="Parent.Parent" %>

Parent Code Behind:

namespace Project
{
    public partial class Parent: System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

Child:

<%@ Master Language="C#" MasterPageFile="~/Parent.Master" AutoEventWireup="true" CodeBehind="Child.master.cs" Inherits="Child.Master" %>

Child Code Behind:

public partial class Child : System.Web.UI.MasterPage {

I'm still getting "Parser Error Message: 'UserMasterPage' is not allowed here because it does not extend class 'System.Web.UI.MasterPage'"

Any Help?

UPDATED with new information

If your class is declared as

namespace Project
{
    public partial class Parent: System.Web.UI.MasterPage
    {

than you should inherit from the Project namespace and then the class Parent:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Parent.master.cs" Inherits="Project.Parent" %>

They must have a direct match otherwise it will not find the class for your master page.


Examples: In the scenario where you have your class inside of a namespace:

namespace Project {
    public partial class Parent : System.Web.UI.MasterPage {

you will use Project.Parent

But if you just have:

public partial class Child: System.Web.UI.MasterPage {

Then you will just use Child

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM