MasterPage.master inheriting from another class that inherits MastPage

倾然丶 夕夏残阳落幕 提交于 2019-12-12 04:46:28

问题


I have my master page inheriting from a class called MasterParent. During compilation, I get an error as following:

Compilation Error:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).

Source Error:

Line 8:  namespace PortfolioApplication
Line 9:  {
Line 10:     public partial class MasterPage : MasterParent
Line 11:     {
Line 12:     }

My code: MasterParent.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PortfolioApplication
{
    public abstract class MasterParent : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        #region "Navigation Buttons"

        protected void btnPortfolio_Click(object sender, EventArgs e)
        {
            Server.Transfer("Portfolio.aspx");
        }
        protected void btnHome_Click(object sender, EventArgs e)
        {
            Server.Transfer("Default.aspx");
        }
        protected void btnContact_Click(object sender, EventArgs e)
        {
            Server.Transfer("Contact.aspx");
        }
        protected void btnResume_Click(object sender, EventArgs e)
        {
            Server.Transfer("Resume.aspx");
        }

        #endregion
    }
}

MasterPage.master.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PortfolioApplication
{
    public class MasterPage : MasterParent 
    {

    }
}

Also: I just tried changing my code in the MasterParent.cs for the class header:

public partial class MasterPage: System.WEb.UI.MasterPage and i am getting the same error about inheritence.

回答1:


You don't have the partial modifier on every definition of MasterPage : MasterParent.



来源:https://stackoverflow.com/questions/13183923/masterpage-master-inheriting-from-another-class-that-inherits-mastpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!