Workshop


Quiz

1.

What are the possible values of the TextBox Web control's TextMode property?

2.

If you wanted to create a multiline text box with 40 columns and 5 rows, what TextBox Web control properties would you need to set?

3.

True or False: Aesthetic settings for text boxes will display the same in all web browsers.

4.

What TextBox Web control property contains the text that was entered by the user?

5.

What Web control that we've examined in previous hours shares a number of properties with the TextBox Web control?

6.

If you set the Text property of a TextBox Web control whose TextMode is set to Password, no text will appear in the text box when viewed through a web browser. Why is this the case?

Answers

1.

The TextBox Web control supports three possible values for its TextMode property. They are MultiLine, Password, and SingleLine. The default property value is SingleLine.

2.

To create such a text box, you would need to set the TextBox Web control's TextMode property to MultiLine, its Columns property to 40, and its Rows property to 5.

3.

False. ASP.NET web controls are rendered differently depending on whether the page is visited by an uplevel or downlevel browser. Downlevel browsers will not render many of the aesthetic settings of the TextBox Web control.

4.

The Text property.

5.

The Label Web control shares a number of properties with the TextBox Web control. For example, both have a Text property, the same set of aesthetic properties, the ID property, and so on. In fact, as we'll see throughout the remainder of the book, all Web controls share a base set of properties.

6.

Password text boxes cannot have their Text property programmatically set, nor do they continue their values across postbacks. The reason is that doing so would serve as a security risk because a nefarious user could simply examine the HTML received by the browser to determine the user's password.

Exercises

  1. For this exercise we'll create an ASP.NET web page that prompts the user for two integers and then computes and displays the integers' greatest common divisor. (The greatest common divisor of two integers a and b, commonly denoted gcd(a,b), is the largest number that divides both a and b without a remainder. For example, gcd(49, 21) is 7.)

    Because the user will need to provide two integers, you'll need two TextBox Web controls. Set the ID property of the first Web control to a, and the second to b. You'll also need to add a Button Web control, as well as a Label Web control. Set the ID property of the Label Web control to results.

    As with the BMI calculator example from the preceding hour, you'll need to create an event handler for the Button Web control's Click event. This event handler will need to compute the greatest common divisor of the values entered into the a and b TextBox Web controls.

    The greatest common divisor of two integers can be quickly computed using the Euclidean Algorithm. If you are not familiar with the details of this algorithm, don't worry, the needed source code is as follows:

    'Assign the maximum of a and b to x and the minimum to y If a.Text < b.Text then   x = b.Text   y = a.Text Else   x = a.Text   y = b.Text End If 'Compute the remainder of x / y z = x mod y While z <> 0   x = y   y = z   z = x mod y End While gcd = y 

    For more information on the Euclidean Algorithm, check out http://en.wikipedia.org/wiki/Euclidean_algorithm.

  2. Given two integers a and b, their least common multiple, commonly denoted lcm(a,b), is the smallest integer that is a multiple of both a and b. For example, the least common multiple of 6 and 4 is 12 because 12 is both a multiple of 6 (6 times 2) and 4 (4 times 3) and is the smallest such multiple. For this exercise, create an ASP.NET web page that accepts two integer inputs from the user and computes the least common multiple.

    Fortunately, computing the least common multiple of two numbers is quite simple after you compute the greatest common divisor of the two numbers. Specifically,

    lcm(a,b) = (a * b) / gcd(a,b) 

    Therefore, for this exercise you should create a function named GCD that takes in two integer inputs and returns an integer value. You can cut and paste the greatest common divisor code that you entered in for exercise 1.

    As with the previous exercise, be sure to include two TextBox Web controls, a Button Web control, and a Label Web control. The Button Web control's Click event handler should compute the least common multiple of the two integers entered by the user using the GCD() function.




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