Creating a New Content Page


After you've successfully completed the template, you really get into it! You can start with the actual page and its individual content. To do so, you simply use the Add New Item command to add a new page of type ContentPage, and name it ContentPage1.aspx. As soon as you've finished, the dialog box shown in Figure 4-2 appears. Here you can choose the desired Master Page if you have more than one. In this example, I just have the one I created earlier.

click to expand
Figure 4-2: Select which Master Page to use.

The new page is now shown in Source view. The content is a bit poor and consists of just one line. The chosen Master Page is referenced by the @Page directive:

 <%@ page language="C#" master="~/MasterPage1.master" %> 

A change to the Design view uncovers the real capabilities of the new developing environment, VS .NET. The new Content Page is shown in the context of the Master Page, which has been placed in the background with the help of alpha blending. The ContentPlaceHolder control is active and can be filled with content, as Figure 4-3 shows.

click to expand
Figure 4-3: You can visually edit your Content Pages.

Instead of the text shown in the example, you can obviously place other controls in the placeholder. In this respect, you have no limitations! You can even use user controls and any source code on the server side or client side without any changes. Let's have a look at the HTML source code to see what's going on inside. The text is being saved within a Content control, which is linked with the ContentPlaceHolder control in the Master Page by the property ContentPlaceHolderId:

 <%@ page language="C#" master="~/MasterPage1.master" %> <asp:content     contentplaceholder    runat="server"> You can visually edit your content page right within the master ... cool stuff! </asp:content> 

Caution

Please be aware you may only place content within the Content controls. You can't place objects outside the areas defined by the Master Page. This includes standard HTML tags such as <html>, <head>, and <body>, which are already included in the Master Page. You can change these only in the corresponding Master Page itself.

Having edited your first Content Page, you may relax for a while and then add as many pages as you'd like. Any changes in the Master Page will become effective at once and automatically on all related pages.

Tip

Instead of defining individual Master Pages with the @Page directive for each page, you may act more globally and define an undocumented attribute in the web.config file:

 <pages    master="~/MasterPage.master" /> 




ASP. NET 2.0 Revealed
ASP.NET 2.0 Revealed
ISBN: 1590593375
EAN: 2147483647
Year: 2005
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net