ASP.NET Creating Content for Master Page
In this tutorial you will learn how to create contents for a Master Page, create a home page, add contents to home page and finally test the home page.
Creating Content for the Master Page
The template for the content is now ready. We shall proceed to define content for the master page by creating an ASP.NET page that is attached to the Master Page. Content pages are specialized forms of .aspx pages that only contain the content. Content can be text or controls. We shall create a content page for the Home page and another for the About page.
To create the home page
1. In Solution Explorer, right-click the name of the Web site, and click Add New Item.
2. Under Visual Studio installed templates, click Web Form.
3. In the Name box, type Home.
4. In Language, click the programming language C#.
5. Select the Select Master Page box, and then click Add.
6. The Select a Master Page dialog box appears.
7. Click MasterPage.master, and then click OK.
Content pages do not have the usual html elements such as < html >, < body > etc. It contains only the content that has to be displayed on the master page by replacing the placeholder for content.
To add content to the home page
1. Switch to Design view.
The content control is displayed as a ContentPlaceHolder control in the master page. The rest of the Master page will appear dimmed because other parts cannot be modified while editing content.
2. In the Properties window, from the drop-down list, click DOCUMENT, and then set Title to ExForSys Home Page.
The title of each content page can be set independently for correct display of title when the page is displayed on the browser. The title information gets stored in the content page’s @Page directive.
3. Right-click the title bar of the Content control, and then click Create Custom Content.
4. In the Content control, type Welcome to the ExForSys Web Site, select the text, and then format the text as a Heading 1.
.
.
5. Press ENTER to create a new blank line in the Content control, and then type Thank you for visiting our site.
The text you add here is not important; you can type any text that will help you recognize this page as the home page.
6. Save the page.
Now create the about page following the steps detailed above. The finished page will look like this.
Testing the Pages 1. Switch to the Home.aspx page, and then press CTRL+F5. ASP.NET merges the content in the Home.aspx page with the layout in the MasterPage.master page into a single page and displays the resulting page in the browser. Notice that the URL of the page is Home.aspx; there is no reference in the browser to the master page. 2. Click the About menu item. The About.aspx page is displayed. It is likewise merged with MasterPage.master page.