views:

176

answers:

4

Does anybody have advice on moving a master page from one solution / application to another?

I have copied a master page from an existing solution to a new one.

The original solution builds and runs fine.

In the new solution the page causes build errors

These are primarily 'variable' not declared.

I have commented out all of the server code for the page, excepting for 2 very simple statements.

statement 1 references a control that is in the original page markup

pgLoginView.EnableViewState = True

Statement 2 references a control that was newly added for test purposes

lblFrogs.Text = "sdfgsd"

It is as though the compiler is unaware of the class members that should be generated from the markup. I have checked the markup files 'Inherits' attribute is set correctly. When I invoke intellisense in the code editor, both objects (lblFrogs and pgLoginView) are listed and in turn list their properties and methods correctly after pressing '.'

Any help or ideas relating to this problem will be greatly appreciated. I am at my wit's end - it was a short journey.

+1  A: 

You should check the generated designer code for you master page - although the .aspx / .master page is used at runtime to create instances of all the controls on your page, at compile time all of the information about what controls are present on the markup is contained in the partial class in the .designer.master file:

public partial class Site1
{
    /// <summary>
    /// ContentPlaceHolder1 control.
    /// </summary>
    /// <remarks> Auto-generated field.</remarks>
    protected global::System.Web.UI.WebControls.ContentPlaceHolder ContentPlaceHolder1;

    // Etc...
}

If that page doesn't contain contain the properly generated code then I'm not really sure what to suggest other than play around with it, or if you get really stuck declare the controls yourself - I've had this problem before but I dont know that much about how the designer code gets generated.

If thats not the porblem then are you sure that visual studio hasnt decided to rename any of the controls?

Kragen
Ah! I didn't know about designer.master being used for compile. I have opened it and indeed the objects are not in there!
RobD
A: 

christian-hayter Seemed to be on the right track. I converted the project to a web site project and the problem went away.

It would appear that the root cause may remain a mystery.

RobD
A: 

Something has definitely gone berserk with the compilation for this page.

I am unable to reference the Profile property. This article from Dino Esposito Says that the Profile object is added to the page as part of the compile process like so:

protected ProfileCommon Profile { get { return ((ProfileCommon)(Context.Profile)); }}

When I do a find in files for ProfileCommon in a working project, I get many results from the the asp.net temporary files. In the broken project, ProfileCommon does not occur in any of the files.

RobD
In clarification of the above - since ProfileCommon is not known, I cannot manually add the property to the page.
RobD
I have attempted various permutations of this advice:http://www.brendancleary.com/?p=41To no avail. The profile property and ProfileCommon are not accessible from the master page or from an added empty test page
RobD
A: 

I have finally found the source of my woe with the Profile object.

Firstly, the profile functionality is only available in the web site type project. However since the project had already been converted to web site type to solve the first issue with referencing page elements, so why did the profile object not becom available?

The answer is that the conversion does not modify the page markup. The location of the code behind needs to be specified with "CodeFile", and the Inherits attribute must have the leading namespace information trimmed off. Example:

<%@ Master Language="vb" AutoEventWireup="true" CodeFile="Default.master.vb" Inherits="_DefaultMaster" %>

RobD