Sams Teach Yourself ASP.NET 2.0 in 24 Hours, Complete Starter Kit

Quiz

1.

What must you do to display formatted text with the Literal Web control?

2.

What must you do to display formatted text with the Label Web control?

3.

True or False: The Literal Web control contains only a single property, Text.

4.

True or False: The Label Web control contains only a single property, Text.

5.

Recall that when the ASP.NET engine executes an ASP.NET web page, it renders the Web controls into their corresponding HTML markup. What factor or factors determine the HTML markup generated by a particular Web control?

6.

What purpose do the Literal and Label Web controls serve?

7.

Why is it said that Web controls are an intermediary between an ASP.NET web page's HTML and source code portions?

8.

True or False: The Label Web control's ForeColor property is ignored by downlevel browsers. (That is, all downlevel browsers display the Text of a Label control as black, regardless of the ForeColor property value.)

Answers

1.

The Literal Web control does not have any formatting properties. Instead, its rendered HTML markup is precisely the value of its Text property. Therefore, if you want to display the Literal Web control with any kind of formatting, you must enter the appropriate HTML tags in the Text property.

2.

The Label Web control contains a number of formatting properties that can be used to specify the resulting text's formatting. Therefore, you can display formatted text by simply setting the appropriate property values.

3.

False. The Literal Web control contains, among others, an ID property.

4.

False. In addition to its Text property, the Label Web control contains a plethora of formatting properties, an ID property, and several other less germane properties.

5.

The HTML markup generated by a Web control depends on two factors: the value of the Web control's properties and the user's browser.

6.

The Literal and Label Web controls are the two Web controls designed to display text.

7.

Web controls are said to be an intermediary between the HTML portion and source code portions of an ASP.NET web page because they are placed in the HTML portion and generate HTML markup, but can be programmatically accessed in the source code portion.

8.

False. It is the Label's BackColor property that is ignored by downlevel browsers.

Exercises

  1. Create an ASP.NET web page that uses a Literal Web control to display the web page's URL. Rather than hard-coding the URL into the Literal's Text property, set the Text property programmatically in the Page_Load event handler. Note that you can obtain the current page's URL via Request.Url.ToString().

    That is, your ASP.NET web page should contain a Literal Web control with its ID property set to some value (say, urlDisplay). Then, in the page's Page_Load event handler, add the following code:

    urlDisplay.Text = Request.Url.ToString()

  2. Create an ASP.NET page and add a Label Web control. Set its Text property to What pretty text! and then set a number of its formatting properties. Feel free to specify whatever formatting property values you'd like, but be sure to set at least five formatting properties. Be sure to try out formatting properties that were not closely examined in this hour.

  3. For this exercise, create an ASP.NET web page that uses a Label Web control to display the IP address of the visitor visiting the web page. (An IP address is a series of four numbers that identifies a computer on the Internet. If you are serving the ASP.NET web pages from your own computer, your IP address will be 127.0.0.1.)

    The visiting user's IP address can be obtained via Request.UserHostAddress. Therefore, to complete this exercise, you will need to create a Label Web control and set its ID property. Then you will need to create a Page_Load event handler in the ASP.NET web page's source code portion that contains the following code:

    LabelID.Text = Request.UserHostAddress

Категории