Content controls have to be top-level controls in a content page


I just downloaded the Visual Web Developer and created a sample project. Here is my first error - "Content controls have to be top-level controls in a content page or a nested master page that references a master page." Learn how to resolve this error.

NOTE: This article was originally published in our old website 07 Dec, 2005.

I downloaded and installed the vwd without any problems this time (well, I had to format my machine 4 weeks back in an attempt to get the vwd beta working, along with my VS.NET 2003!)

I created a new ASP.NET web site using the visual web developer. I added a login page and a master page. All I did in the login page is, set the master page property to point to the empty master page I created. I am yet to use any controls in the login page or master page.

Surprisingly, I got the following error when I tried to run the login page:

"Content controls have to be top-level controls in a content page or a nested master page that references a master page."

Content controls have to be top-level controls in a content page



I spent 2-3 minutes to carefully read the error message. It is quite obvious! I should not have any content in the "content page".

I looked into my content page. I am an old ASP.NET guy! I created the ASPX page just like the old way. So it came with all default html tags.

Here is the deal - if you are using master pages,you should not have any content outside the <asp:content> tag.

The mistake I did was, I did not select the checkbox "select master page" while creating the aspx page.

I deleted all html tags from my Login.aspx and added just the following:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Login.aspx.vb" Inherits="Login" MasterPageFile="~/TrackerMain.master" %>

<asp:content id="Content1" contentplaceholderid="ContentPlaceHolder1" runat="server">
Welcome!
</asp:content>

where ContentPlaceHolder1 is the id of the PlaceHolder control in the master page. It worked fine.

I learned some nice lessons from this exercise:

1. I should spend atleast 1 hour to read 'how to work with aspx pages in ASP.NET 2.0', before I start a project.

2. Watch out for signs when you are not familiar with the road! When we create a new web page using vwd, there is a check box "select master page". If I check the box, vwd will do the right job and create the content page just the way it need to be.


Comments



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: