Answers for Day 3

IOTA^_^    

Sams Teach Yourself ASP.NET in 21 Days, Second Edition
By Chris Payne
Table of Contents
Appendix A.  Answers to Quiz Questions


Quiz

1:

When should you use a for loop? A while loop?

A1:

Use a for loop when you know the number of times the code should execute. Use a while loop when you don't know this.

2:

What is the output of the following code snippet?

 Dim I as integer = 5 Do    Response.Write(I & " ")    I = I + 2 Loop Until I > 10 
A1:

The output is

 5 7 9 
3:

What is the output of the following code snippet?

 Dim I as integer = 5 Do    I = I + 2  Response.Write(I & " ") Loop Until I > 10 
A1:

The output is

 7 9 11 
4:

What are the standard event handler parameters for ASP.NET pages?

A1:

The standard parameter list is (Sender as Object, e as EventArgs).

Exercise

Q1:

Create an ASP.NET page with a class that represents you, with properties that describe your hair color, eye color, and birth date. Use the DayOfWeek property of the DateTime data type to determine the day of the week of your birthday. The DayOfWeek property returns an value from the DayOfWeek enumeration convert this into a string representing the day. Call this method whenever a user clicks the Submit button, and print the output to the browser.

Hint: You'll need to use the new keyword with the DateTime data type. Pass three parameters into the new DateTime data type: the year, month, and day of month, in that order. For example:

 dim MyDate as new DateTime(2002,1,1)   'January 1, 2002 
A1:

Here's the code:

 1:    <%@ Page Language="VB" %> 2: 3:    <script runat="server"> 4:       Class Chris 5:          public dtBirthDay as DateTime = #6/27/78# 6:          public strHairColor as string = "Brown" 7:          public strEyeColor as string = "Brown" 8: 9:          function GetDayOfWeek() 10:             dim strDay as string 11: 12:             select case dtBirthDay.DayOfWeek 13:                case 0 14:                   return "Sunday" 15:                case 1 16:                   return "Monday" 17:                case 2 18:                   return "Tuesday" 19:                case 3 20:                   return "Wednesday" 21:                case 4 22:                   return "Thursday" 23:                case 5 24:                   return "Friday" 25:                case 6 26:                   return "Saturday" 27:             end select 28:          end function 29: 30:       End Class 31: 32:       sub Button_Click(Sender as Object, e as EventArgs) 33:          dim objChris as new Chris 34:          Response.write(objChris.GetDayOfWeek) 35:       end sub 36: 37:    </script> 38: 39:    <html><body> 40:       <form runat="server"> 41:          <asp:button  Text="Submit" 42:             runat=server 43:             OnClick="Button_Click"/><p> 44:       </form> 45:    </body></html> 


    IOTA^_^    
    Top


    Sams Teach Yourself ASP. NET in 21 Days
    Sams Teach Yourself ASP.NET in 21 Days (2nd Edition)
    ISBN: 0672324458
    EAN: 2147483647
    Year: 2003
    Pages: 307
    Authors: Chris Payne

    Similar book on Amazon

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