Sams Teach Yourself ASP.NET in 21 Days (2nd Edition)

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:

What are the five Validation controls?

A1:

RequiredFieldValidator, CompareValidator, RangeValidator, RegularExpressionValidator, and CustomValidator.

2:

True or false: Validation controls are created on the client side.

A1:

False. Validation controls are created server-side, just like all other server controls.

3:

What two properties should every Validation control have?

A1:

ControlToValidate and ErrorMessage.

4:

What does the clienttarget=downlevel parameter do?

A1:

It makes ASP.NET believe you're developing for an older browser, disabling all DHTML events (including Validation controls).

5:

Assuming you have two server controls, tbName and tbAge, will the following validator work?

<asp:CompareValidator runat="server" ControlToValidate="tbName" ValueToCompare="tbAge" ErrorMessage="Error!"/>

A1:

No, you should use ControlToCompare instead of ValueToCompare.

6:

What's the property you need to set for the CustomValidator control that specifies the event handler?

A1:

OnServerValidate.

Exercise

Q1:

Build a login page similar to Listing 7.7, but build it into a user control. Handle all validation inside the user control, as opposed to the containing ASP.NET page.

A1:

1: <script runat="server"> 2: sub Submit(Sender as Object, e as EventArgs) 3: if Page.IsValid then 4: 'do something 5: end if 6: end sub 7: 8: sub ValidateThis(Sender as Object, args as _ 9: ServerValidateEventArgs) 10: if len(args.Value) < 8 then 11: args.IsValid = false 12: else 13: args.IsValid = true 14: end if 15: end sub 16: </script> 17: 18: <asp:Label runat="server" /> 19: <table> 20: <tr> 21: <td valign="top">Username:</td> 22: <td valign="top"> 23: <asp:Textbox runat="server" 24: /><br> 25: <asp:CustomValidator runat="server" 26: OnServerValidate="ValidateThis" 27: OnClientValiate="validateLength" 28: Display="Dynamic" 29: ControlToValidate="tbUserName" 30: ErrorMessage="The username must be 8 characters or longer"/> 31: </td> 32: </tr> 33: <tr> 34: <td valign="top">Password:</td> 35: <td valign="top"> 36: <asp:Textbox runat="server" 37: TextMode="password" /> 38: </td> 39: </tr> 40: <tr> 41: <td align="right" colspan="2"> 42: <ASP:Button runat="server" 43: OnClick="Submit" 44: text="Submit" /> 45: </td> 46: </tr> 47: </table>


    IOTA^_^    
    Top

    Категории