Вы находитесь на странице: 1из 7

Richard Tham - ASP.

NET Training Part 2


Try these questions:
1. Write an ASP.NET script that gets from the user the radius of a circle and outputs
to a label display that shows the diameter, circumference and area.
(Formula: diameter = 2r ; circumference = 2r ; area = r r)
2. Write an ASP.NET script that reads an integer and determines and outputs on a
label to show whether it is an odd or even number.
3. Write an ASP.NET script that reads 2 integers and determines and outputs on a
label that display the first is a multiple of the second.

ASP.NET Web Controls for Displaying Text


Using the Literal Web Control
To illustrate the Literal's behavior, let's create an ASP.NET page that has a Literal control.
Start by creating a new ASP.NET web page named LiteralControl.aspx; as always,
make sure that the Language selected is Visual Basic and that the Place Code in a
Separate File check box is checked. Next, drag the Literal control from the Toolbox onto
the page.

Richard Tham - ASP.NET Training Part 2

1. Take a moment to change the Literal Web control's Text property to Hello,
World!.
2. Now that we've added this Literal Web control and set its Text property, let's
view this ASP.NET web page through a browser. Go to the Debug menu and
choose Start Without Debugging.

Richard Tham - ASP.NET Training Part 2

1. Let's create an ASP.NET web page that uses a Label Web control to display the
current date and time. Start by creating a new ASP.NET web page named
LiteralTime.aspx, and then drag and drop a Literal Web control onto the
designer. We don't need to set the Text property through the Properties window
because we will be setting this property programmatically. We should, however,
rename the Literal Web control's ID property from the ambiguous Label1 to
something more descriptive, such as currentTime.
2. After we've added the Literal Web control and set its ID property to currentTime,
we're ready to add the needed source code. Start by creating an event handler for
the page's Load event by double-clicking in the Design view region or going to
the source code portion and selecting (Page Events) from the left drop-down list
and Load from the right. For this ASP.NET web page, we want to have the Literal
Web control's Text property set to the current date and time whenever the page is
visited. Therefore, we will do so in the Page_Load event handler.
Enter the following code into your Page_Load event handler:
currentTime.Text = DateTime.Now
3. After you have entered this source code content, save the ASP.NET web page and
run it.

Richard Tham - ASP.NET Training Part 2

Using the Label Web Control


1. Start by creating an ASP.NET page named LabelControl.aspx; then drag and
drop a Label Web control onto the page
2. First, let's set the Label Web control's Text property to Hello, World!.
3. After the Text property has been set, let's make it display its content in a bold
font. To accomplish this, click the Label Web control, which will load the
control's properties in the Properties window. One of the properties listed is Font.
To the left of this property name, you'll find a plus, which indicates that this
property has subproperties. Click the plus to expand these subproperties.

4. One of these subproperties is Bold, which defaults to a value of False. Go ahead


and select true from the drop-down list. This has the effect of making the Label
Web control's text in the designer appear bold, as you can which shows how the
control looks after the Bold subproperty has been set to true.

Richard Tham - ASP.NET Training Part 2

Looking at the Color Properties


1. Let's create a new ASP.NET web page to try out these two color properties. Start
by creating an ASP.NET web page named ColorLabel.aspx, and drag and drop
a Label Web control onto the page. After adding the Label Web control, change
the Text property to: This is a test of the color properties
2. Now, let's set the BackColor to Navy and the ForeColor to White.

Richard Tham - ASP.NET Training Part 2

Examining the Border Properties


1. Let's create an ASP.NET web page that displays a border around the text
displayed by a Label Web control. Start by creating a new ASP.NET page titled
BorderLabel.aspx. Drag and drop a Label Web control onto the page and set the
Label's Text property to: Testing the border properties. Next, click the
Label Web control's BorderStyle property. This should open a drop-down list
that contains various options for the style of border to be placed around the Label
Web control.
2. Go ahead and select the Solid option for the BorderStyle property. In the
designer you will see a solid border appear around the edges of the Label Web
control.
3. Go ahead and opt to have our Label Web control's BorderColor property set to
Red, a color from the Web tab.
4. In addition to the BorderStyle and BorderColor properties, there's a
BorderWidth property as well. Go ahead and enter a value of 2 as the
BorderWidth property, which will create a border 2 pixels wide

Richard Tham - ASP.NET Training Part 2

Delving into the Font Properties


1. Create a new ASP.NET page named LabelFont.aspx, and drag and drop a Label
Web control onto the designer. Set this Web control's Text property to Working
with the Font properties. Next, expand the Label Web control's Font
property by clicking on the plus to the left of the Font property name. This will
expand the Font property, listing the subproperties.
2. Let's set some of the Font property's subproperties. Start by setting the Italic
subproperty to true, which should make the Label's text appear in an italic font in
the designer. Next, under the Name property, choose the font name Arial. When
selected, the Label Web control in the designer should be updated to show its text
in the Arial font. Finally, set the Size subproperty to 22pt. This will cause the
Label Web control's text in the designer to enlarge to a 22-point size.

Вам также может понравиться