Workshop


Quiz

1.

What is the purpose of a ContentPlaceHolder control in a master page?

2.

True or False: A master page can have no more than one ContentPlaceHolder Web control.

3.

What content is an ASP.NET page composed of when it is set up to inherit a master page?

4.

What steps must be taken to create a new ASP.NET page that inherits a master page?

5.

What steps must be taken to have an existing ASP.NET page inherit a master page?

6.

How do you have an ASP.NET page use the master page's default content for a given region?

7.

True or False: Master pages can contain a server-side source code portion.

Answers

1.

The ContentPlaceHolder control indicates a region in the master page where ASP.NET pages that inherit the master page can optionally define the content. All other content in a master page is not editable by the inheriting ASP.NET page.

2.

False. A master page can have an arbitrary number of ContentPlaceHolder controls.

3.

ASP.NET pages that inherit master pages contain a reference to the master page in their <%@ Page %> directive (specifically, MasterPageFile="pathToMasterPage") as well as a Content Web control for each ContentPlaceHolder region in the master page for which the page wants to provide a custom value.

4.

To have a newly created ASP.NET page inherit from a master page, check the Select Master Page check box in the Add New Item dialog box. Doing so will bring up a list of the master pages in the project, from which you can select the one that the page inherits from.

5.

If you have an existing ASP.NET page that you want to inherit from an existing master page, start by adding the appropriate MasterPageFile attribute to the page's <%@ Page %> directive. Next, replace the page's declarative markup portion with a Content Web control for each of the master page's ContentPlaceHolder controls. Some tips for accomplishing this step are discussed in the "Having an Existing Page Inherit from a Master Page" section.

6.

An ASP.NET page that inherits a master page can opt to use the master page's default content for a given ContentPlaceHolder. To accomplish this, simply remove the ASP.NET page's Content control that corresponds to the ContentPlaceHolder for which you want to use the default content. You can do this by manually removing the Content control from the Source view or by going to the Design view, right-clicking on the Content region, and selecting the Default to Master's Content option.

7.

True.

Exercises

  1. In the preceding hour we looked at how to provider user account support in an ASP.NET website. Commonly, such sites have various user account-related Web controls on every page.

    Return to the examples from the preceding hour and create a master page that has a header region, left-side region, and main region. In the header region, put the website's title and the LoginStatus control. (Recall that the LoginStatus control displays a Login link for anonymous users and a Logout link for those who are logged in.) In the left-side region, use a LoginView control. In the control's Anonymous Template, put a Login Web control; in the Logged In Template, display the message "Welcome back, username" and include a Logout link. Figure 21.13 shows a diagram of the site template that your master page should implement.

    Figure 21.13. The site design contains three regions.

    After you have created this master page, take a moment to convert the existing pages in the site to inherit this master page. Furthermore, create at least one new page that inherits from this master page.




Sams Teach Yourself ASP. NET 2.0 in 24 Hours, Complete Starter Kit
Sams Teach Yourself ASP.NET 2.0 in 24 Hours, Complete Starter Kit
ISBN: 0672327384
EAN: 2147483647
Year: 2004
Pages: 233

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