Search code examples
asp.netvwdexpress

ASP.NET @MasterType Directive Not Working


Using VWD 2008 Express and C#. I created some web pages without using a master page. Later decided I wanted to use a master page so I thought I would do a test page first. Created the master page, then Add New Item (TestMstr.aspx) and Select Master Page option. Added public properties of type 'string' to MasterPage.master.cs so I could use these to set label text in the master page by doing a property set from the content page. This required @MasterType page directive in the content page:

<%@ MasterType virtualpath="~/MasterPage.master" %>

Everything worked great on the test page, then things started to get interesting. I started reformatting my existing pages to use the master page, but now I am getting errors on my call to the public properties from the edited page (RTM23a.aspx):

Master.PageTitle = "My New Page Title";

Gives this error when trying to run the page: 'System.Web.UI.MasterPage' does not contain a definition for 'PageTitle' and no extension method 'PageTitle' accepting a first argument of type 'System.Web.UI.MasterPage' could be found (are you missing a using directive or an assembly reference?).

This exact call works fine from the TestMstr. I know the contents of TestMstr and RTM23a are the same because I have literally copied TestMstr to Report1 and just changed TestMstr to RTM23a. In RTM23a, typing 'Master.' gives intellisense showing the PageTitle property. The Build->Build Page, Build->Build Web Site, and Build->Rebuild Web Site menu items give no errors - only warnings. A CMD shell file compare (FC) for the two files follows.

ASPX files:

Comparing files TestMstr.aspx and RTM23A.ASPX
***** TestMstr.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="TestMstr.aspx.cs" Inherits="TestMstr" %>
<%@ MasterType virtualpath="~/MasterPage.master" %>
***** RTM23A.ASPX
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="RTM23a.aspx.cs" Inherits="RTM23a" %>
<%@ MasterType virtualpath="~/MasterPage.master" %>
*****

Code behind files:

Comparing files TestMstr.aspx.cs and RTM23A.ASPX.CS
***** TestMstr.aspx.cs

public partial class TestMstr : System.Web.UI.Page
{
***** RTM23A.ASPX.CS

public partial class RTM23a : System.Web.UI.Page
{
*****

***** TestMstr.aspx.cs
  private int _iMon, _iYr;
  private RptTestMstr _StateDur;

***** RTM23A.ASPX.CS
  private int _iMon, _iYr;
  private RptRtaWFStages _StateDur;

*****

***** TestMstr.aspx.cs
  {
    _StateDur = new RptTestMstr(_iYr, _iMon);
    _StateDur.RtaInput = this.txtRtaNos.Text;
***** RTM23A.ASPX.CS
  {
    _StateDur = new RptRtaWFStages(_iYr, _iMon);
    _StateDur.RtaInput = this.txtRtaNos.Text;
*****

***** TestMstr.aspx.cs

  // End TestMstr class definition
}
***** RTM23A.ASPX.CS

  // End RTM23a class definition
}
*****

What could possibly be causing this problem? The pages are in the same project, and everything looks correct, but one runs and the other doesn't. To be clear, TestMstr was created by selecting the master page from the beginning, while RTM23a was originally created without selecting the master page, then edited to look like TestMstr.

Update: RTM23a works fine on the server. It seems simply that my debug is broken.


Solution

  • File system copied RTM23a and code behind outside the project folder, then deleted the files using the IDE UI. Next, with the project still open in VWD, file system copied the files back into the project folder and used Add Existing Item... menu to add them back. So problem solved, BUT mystery remains. Had previously also shut down the ASP.NET development server to no avail.