views:

55

answers:

4

I'm trying to make my masterpage work with my content page, allowing the content page to access the master page controls. I get the error:

Parser Error Message: The 'mastertype' directive must have exactly one attribute: TypeName or VirtualPath

This is on the lines:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="viewProduct.aspx.cs" Inherits="AlphaPackSite.viewProduct"
    MasterPageFile="MasterPages/Main.master"
    title="Hi there!"
%>
<%@ MasterType TypeName="Main" VirtualPath="MasterPages/Main.master" %>

My master page is:

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

I'm a bit confused with namespaces and such so may have got them wrong, but all pages are in the same namespace now I beleive.

Update

When I turn it to:

<%@ MasterType VirtualPath="MasterPages/Main.master" %>

I keep getting the error:

Compiler Error Message: CS0030: Cannot convert type 'AlphaPackSite.Main' to 'ASP.masterpages_main_master'

Source Error:

Line 147:        public new ASP.masterpages_main_master Master {
Line 148:            get {
Line 149:                return ((ASP.masterpages_main_master)(base.Master));
Line 150:            }
Line 151:        }
A: 

Try:

<%@ MasterType TypeName="AlphaPackSite.Main"  %>
David_001
Thanks for the answer, same error as other answers, i've written it in an update to the question
Tom Gullen
+2  A: 

As the error says, @MasterType expects only one parameter. Try just:

<%@ MasterType VirtualPath="MasterPages/Main.master" %>

See http://msdn.microsoft.com/en-us/library/ms228274.aspx for more info.

Michael Shimmins
Thanks, I'd tried that already and it throws a different error :s
Tom Gullen
Which error does it generate now?
Michael Shimmins
I put it under the heading 'Update' in the question description
Tom Gullen
+2  A: 

Unless you want to keep a reference of your master page in the current page (in which this code is written), I'd suggest you remove the <%@ MasterType VirtualPath="MasterPages/Main.master" %> line.

This line provides a way to access your page's master page (such as when you've to change a label on the master page or the menu needs to add a few more items etc.). If the content of your master page does not require any changes/updates from your content page there's not need to use the MasterType tag. Because by using both MasterPageFile="MasterPages/Main.master and MasterType, you're confusing the compiler (even though the master page is same).

Update
If you have to keep the MasterType tag, then remove the MasterPageFile="MasterPages/Main.master attribute from the page directive.

Sidharth Panwar
A: 
lakhlaniprashant.blogspot.com