Master Page Weirdness - “Content controls have to be top-level controls in a content page or a nested master page that references a master page.”

后端 未结 13 1788
借酒劲吻你
借酒劲吻你 2020-12-05 06:28

This is weird. I added a brand new Web Application project to my solution in Visual Studio 2008.

Created a master page. Made zero modifications. Created a new we

相关标签:
13条回答
  • 2020-12-05 06:32

    In my case runat="server" was missing in the asp:content tag. I know it's stupid, but someone might have removed from the code in the build I got.

    It worked for me. Someone may face the same thing. Hence shared.

    0 讨论(0)
  • 2020-12-05 06:35

    Better late than never i suppose... you get the option to set the MASTERPAGE only of you are developing a WEB SITE (FILE>NEW>WEBSITE)... but not when you create an ASP.NET project (FILE>NEW>PROJECT) - there you have to set the Masterpage using the properties of the newly created webform and it's up to you to modify the ASPX source to make it master page compliant (ie, removing the stock HTML, etc...)

    0 讨论(0)
  • 2020-12-05 06:35
    protected void Page_PreInit(object sender, EventArgs e) 
    { 
     if (Membership.GetUser() == null) //check the user weather user is logged in or not
        this.Page.MasterPageFile = "~/General.master";
     else
        this.Page.MasterPageFile = "~/myMaster.master";
    }
    
    0 讨论(0)
  • 2020-12-05 06:36

    When you created the WebForm, did you select the Master page it is attached to in the "Add New Item" dialog itself ? Or did you attach it manually using the MasterPageFile attribute of the @Page directive ? If it was the latter, it might explain the error message you receive.

    VS automatically inserts certain markup in each kind of page. If you select the MasterPage at the time of page creation itself, it does not generate any markup except the @Page declaration and the top level Content control.

    0 讨论(0)
  • 2020-12-05 06:36

    For some reason, there is no option in the create page dialogue to select a master page. I have tried both programatically declaring the MP and by updating the property in the Properties pane. – NoCarrier 13 mins ago

    I believe its because i'm using a "web application" vs a "web site" – NoCarrier 9 mins ago

    Chances are it is in the <@PAGE> tag where your problem is. That said, it doesnt make a difference if you are using a Web Application or not. To create a Child Page, right click on your master page in the Solution Explorer and choose Add Content Page.

    0 讨论(0)
  • 2020-12-05 06:41

    Just got this problem. It was because we had a tag ending with double slashes:

    <//asp:HyperLink>
    
    0 讨论(0)
提交回复
热议问题