MasterType directive error

Last post 12-14-2008 11:07 PM by rfcarter. 6 replies.

Sort Posts:

  • MasterType directive error

    12-08-2008, 6:34 PM
    • Member
      point Member
    • rfcarter
    • Member since 12-08-2008, 6:30 PM
    • Posts 4
    I am trying to set a strongly typed referece to my Master Page from content 
    pages and get the following error when I build:
    
    Error	1	The type name 'ISOTimeSheets' does not exist in the type 
    'ISOTimeSheets.ISOTimeSheets'
    
    The code inserted into the designer.cs for the web page is the following:
    
            /// <summary>
            /// Master property.
            /// </summary>
            /// <remarks>
            /// Auto-generated property.
            /// </remarks>
            public new ISOTimeSheets.ISOTimeSheets Master {
                get {
                    return ((ISOTimeSheets.ISOTimeSheets)(base.Master));
                }
    
    The line I added to my content page is:
    
    <%@ MasterType VirtualPath="~/ISOTimeSheets.Master" %>
    
    The project is not strongly named due to a vendor component that I am using, 
    but just to see of this was the issue I strongly named the project and the 
    error still exists.  There is not much help on the web other than showing how 
    to use the directive.  If I cannot get this to work with the directive does 
    someone have a code snippet that would allow me to loosely couple?  I saw one 
    vague reference to loose coupling but no examples in my reseatch thus far.
    
    What I am trying to accomplish is the establishment of some properties on 
    the master page so I can reduce, and hopefully eliminate, the need to session 
    vaiables in my application.
    
    Thanks
    
  • Re: MasterType directive error

    12-11-2008, 4:21 AM
    Answer

    As a solution, I wrote a demo for your reference,

    Maser Page:

    <%@ Master Language="C#" %>
    <%@ Import Namespace="System.Data" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        string strTitle = "ASP.NET";
        public string TheTitle
        {
            get 
            {
                return strTitle;
            }
            set 
            {
                strTitle = value;
            }
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Demo</title>
        <asp:ContentPlaceHolder id="head" runat="server">
        </asp:ContentPlaceHolder>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">        
            </asp:ContentPlaceHolder>
        </div>
        </form>
    </body>
    </html>
    

    Page:

    <%@ Page Language="C#" MasterPageFile="~/MasterPage/MasterType20081211.master" Title="" %>
    <%@ MasterType VirtualPath="~/MasterPage/MasterType20081211.master" %>
    
    <script runat="server">
    
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(Master.TheTitle);
            Master.TheTitle = "Microsoft";
            Response.Write("<br />");
            Response.Write(Master.TheTitle);                  
        }
    </script>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    </asp:Content>
     
    Hong-Gang Chen
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: MasterType directive error

    12-14-2008, 2:19 PM
    • Member
      point Member
    • rfcarter
    • Member since 12-08-2008, 6:30 PM
    • Posts 4

    I have tried to replicate this code in my project with no success.  The master page I have was in the root and I moved it to a sub-folder as in your example and still not working.  Could it be that the name of the masterpage is the same as the project (namespace)?  If so, where can I change the reference to the master page?  If I rename the master and change the reference in the content pages, the site works fine but the directive is still broken when I insert it (the old name of the master page is being reference).  It seems obvious that I have done something incorrectly in the setup of the master page since this reference will not woork for me.  Is there an area I can go to change the references and fix the type error withour re-creating the project?

     Alos, I have no code in the aspx itself but am trying to keep all code in the code-behind?  I assume this is not a problem since I can reference controls on the master page using find control from there.

     Can you please provide a loosely typed example to reference to the master page properties as well?

    thanks

  • Re: MasterType directive error

    12-14-2008, 9:07 PM

    Hi rfcarter,

    1. I have tested my code, it woks;

    2. Please check follow two lines,

    <%@ Page Language="C#" MasterPageFile="~/MasterPage/MasterType20081211.master" Title="" %>
    <%@ MasterType VirtualPath="~/MasterPage/MasterType20081211.master" %>

    if you want to the strong name working, you need to keep the path of MasterPageFile and VirtualPath are same.

    Hong-Gang Chen
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: MasterType directive error

    12-14-2008, 10:48 PM
    • Member
      point Member
    • rfcarter
    • Member since 12-08-2008, 6:30 PM
    • Posts 4

    I did not mean to imply that your code did not work, but was stating that mine still did not. The path to the master page and the virtual path are the same.  I have no doubt that you are exhibiting the correct method since that is the same way that I have seend it done in everything that I have read to date.  I have decide to go with the loosely typed solution and that is working for me at present.

    Thank you for your response.

  • Re: MasterType directive error

    12-14-2008, 11:03 PM

    So have you sovle your problem yet?

    Hong-Gang Chen
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: MasterType directive error

    12-14-2008, 11:07 PM
    • Member
      point Member
    • rfcarter
    • Member since 12-08-2008, 6:30 PM
    • Posts 4

    In a manner.  I use the following:

    ISOTimesheetes myMaster=(ISOTimeSheets)(Page.Master);

    This gives me a refrence to the master page that the content page is on and allows access to all the properties.  I still get the missing type error when using the strong reference.  I will try that on a future project but since this solution works and I have to get the site done I will use it for now.

Page 1 of 1 (7 items)