Answers for Day 2

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:

How does ASP.NET maintain the state of server controls?

A1:

By placing hidden HTML tags in the ASP.NET page that remember the values entered.

2:

What namespace do the ASP.NET Page and LiteralControl classes belong to?

A1:

 System.Web.UI 
3:

What are the seven namespaces automatically imported into every ASP.NET page?

A1:

System, System.Collections, System.IO, System.Web, System.Web.UI, System.Web.UI.WebControls, and System.Web.UI.HTMLControls.

4:

What does "type-safe" mean?

A1:

This ensures that an object only references memory locations that it's allowed to, preventing data corruption. Essentially, it means that one type of object cannot be used as another type accidentally.

5:

What is the Common Language Specification?

A1:

It's the basic subset of features provided by the CLR that are found in every modern object-oriented programming language. The CLS ensures that cross-language objects can interact with each other.

Exercises

1:

Create a simple ASP.NET page in VB.NET or C# that accepts two number inputs from the user and displays their product when the Submit button is clicked. Use two text box controls, a label control, and a Submit button control. Also use the standard event handler code defined in the "Code Declaration Blocks" section of today's lesson. Try using the Cint() function to convert the text in the text boxes to integers for multiplication, such as Cint(tbNumber1.Text).

Follow Listing 2.1 for guidance.

A1:

The code for the ASP.NET page is as follows:

 1:    <%@ Page Language="VB" %> 2:    <script language="VB" runat="server"> 3:       Sub btSubmit_Click(Sender As Object, E As EventArgs) 4:          lblMessage.Text = Cint(tbNumber1.Text) * _ 5:             Cint(tbNumber2.Text) 6:       End Sub 7:    </script> 8:    <html> 9:    <body> 10:       <font size="5">Sam's Teach Yourself ASP.NET in 21 Days: 11:       Day 2, Exercise 1</font><hr><p> 12: 13:       <form runat="server"> 14: 15:          Number 1: <asp:textbox  runat=server/> 16:          Number 2: <asp:textbox  runat=server/> 17:          <asp:button  Text="Submit" 18:             OnClick="btSubmit_Click" runat=server/><p> 19:          <asp:label  font-size="20pt" 20:             runat=server/> 21:       </form> 22: 23:    </body></html> 
2:

Build upon the previous exercise by providing multiple Submit buttons that perform the basic arithmetic operations, essentially creating a calculator.

A1:

The code for the ASP.NET page is as follows:

 1:    <%@ Page Language="VB" %> 2:    <script runat="server"> 3:       Sub btAdd_Click(Sender As Object, E As EventArgs) 4:          lblMessage.Text = "The answer is: " & _ 5:             Cint(tbNumber1.Text) + Cint(tbNumber2.Text) 6:       End Sub 7: 8:       Sub btSubtract_Click(Sender As Object, E As EventArgs) 9:          lblMessage.Text = "The answer is: " & _ 10:             Cint(tbNumber1.Text) - Cint(tbNumber2.Text) 11:       End Sub 12: 13:       Sub btMultiply_Click(Sender As Object, E As EventArgs) 14:          lblMessage.Text = "The answer is: " & _ 15:             Cint(tbNumber1.Text) * Cint(tbNumber2.Text) 16:       End Sub 17: 18:       Sub btDivide_Click(Sender As Object, E As EventArgs) 19:          lblMessage.Text = "The answer is: " & _ 20:             Cint(tbNumber1.Text) / Cint(tbNumber2.Text) 21:       End Sub 22:    </script> 23:    </html><body> 24: 25:       <font size="5">Sam's Teach Yourself ASP.NET in 21 Days: 26:       Day 2, Exercise 2</font><hr><p> 27: 28:       <form runat="server"> 29: 30:          Number 1: <asp:textbox  runat=server/> 31:          <br> 32:          Number 2: <asp:textbox  runat=server/> 33:          <p> 34:          <asp:button  Text="   +   " 35:             OnClick="btAdd_Click" runat=server/> 36:          <asp:button  Text="   -   " 37:             OnClick="btSubtract_Click" runat=server/> 38:          <asp:button  Text="   *   " 39:             OnClick="btMultiply_Click" runat=server/> 40:          <asp:button  Text="   /   " 41:             OnClick="btDivide_Click" runat=server/><p> 42:          <asp:label  font-size="20pt" 43:             runat=server/> 44: 45:       </form> 46:    </body> 47:    </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