Adding Validation Controls

IOTA^_^    

ASP.NET Developer's JumpStart
By Paul D. Sheriff, Ken Getz
Table of Contents
Chapter 25.  Creating Mobile Web Applications


When you're creating mobile Web pages, you're likely to want to validate user input before submitting it to the server. The Microsoft Mobile Internet Toolkit provides the same set of validation controls you'll find in standard ASP.NET pages.

NOTE

Unlike standard ASP.NET validation controls, the Microsoft Mobile Internet Toolkit's validation controls perform no client-side validation. All validation for these controls takes place on the server.


On the first form, you might want to require that the user supply a password before retrieving other information. You can use the RequiredFieldValidator control to accomplish this. Follow these steps to add this control to your page:

  1. Select frmMain.

  2. Click txtPassword so that it has the focus.

  3. Double-click the RequiredFieldValidator control in the Toolbox to add a new control immediately beneath the text box.

  4. Set the properties for the new RequiredFieldValidator control as shown in Table 25.5.

    Table 25.5. Use These Properties for the RequiredFieldValidator Control
    Property Value
    ID rvalPassword
    ControlToValidate txtPassword
    ErrorMessage Enter a password

  5. Unless you check for the validity of the data programmatically, nothing keeps the code in the page from navigating from one form to another. Therefore, modify the cmdGo_Click procedure so that it looks like this:

     Private Sub cmdGo_Click( _  ByVal sender As System.Object, _  ByVal e As System.EventArgs) _  Handles cmdGo.Click   If rvalPassword.IsValid Then     FillCountry()     ActiveForm = frmCountry   End If End Sub 
  6. Test the project: Browse the page within Internet Explorer, a handheld device simulator, or a real device. In any case, you should be required to enter a password (any password), and you should see the data loaded into the controls.


    IOTA^_^    
    Top


    ASP. NET Developer's JumpStart
    ASP.NET Developers JumpStart
    ISBN: 0672323575
    EAN: 2147483647
    Year: 2002
    Pages: 234

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