0

I am trying to add a codefile to my asp.net masterpage. I had it working properly on an individual page, but cannot do so on my master page.

In my aspx master page I have:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Master.cs" Inherits="Master.Master" %>

Then I have a file called:

Master.cs

and the code below is:

namespace Master
{
    using System;

    public partial class Master : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("ALEX");
            Response.End();
        }
    }
}

as far as I can see all my declarations are correct, but the error I get is:

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).

and the line:

Line 5:      public partial class Master : System.Web.UI.Page

is in red. I have had this error before but I am sure I have all my code correctly, so am not sure why I m getting this error?

Maybe the master file needs a different setup, or it works differently on the masterpage?

1 Answer 1

2

When defining a master page code behind class, the base class to inherit is System.Web.UI.MasterPage, not System.Web.UI.Page.

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

Comments

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.