Search code examples
c#asp.netmaster-pagesscopecontent-pages

Can't find ASP.NET master page


I'm trying to get my content page to be able to access an ASP:Literal on a master page.

I have my content page as:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="viewProduct.aspx.cs" Inherits="AlphaPackSite.viewProduct" Title="Hi there!" %>
<%@ MasterType TypeName="Main" %>

Then my master page called Main.master has:

<asp:Literal runat="server" ID="lblBasket" />

But from the content page when I try and do:

Master.basket.Text = "test";

I get:

Error 46 The type or namespace name 'Main' could not be found (are you missing a using directive or an assembly reference?)

The error is on the designer page:

public new Main Master {
    get {
        return ((Main)(base.Master));
    }
}

My master page code behind is:

namespace AlphaPack.MasterPages
{
    public partial class Main : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.IsLoggedIn = Request.IsAuthenticated;
        }

        public bool IsLoggedIn
        {
            get { return this.ViewState["isLoggedIn"] as bool? ?? false; }
            set { this.ViewState["isLoggedIn"] = value; }
        }
    }
}

Solution

  • Is the designer within your AlphaPack.MasterPages namespace?

    The MasterType isn't fully qualified, should it be? Don't you have to provide a path as well? (Not familiar with, sorry).

    How does this respond if you use a MasterPageFile reference instead of a MasterType?