ASP.NET
  Home arrow ASP.NET arrow Page 2 - Completing a Web Form in ASP.NET
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Completing a Web Form in ASP.NET
By: Murach Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 23
    2006-06-15

    Table of Contents:
  • Completing a Web Form in ASP.NET
  • How to use the required field validator
  • How to add code to a form
  • How to use page and control events
  • How to run a web site with the built-in development server

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Completing a Web Form in ASP.NET - How to use the required field validator


    (Page 2 of 5 )

    To use the required field validator, you set the properties shown in the table at the top of figure 2-13. These are the properties that are used by all the validators.

    To start, you associate the validation control with a specific input control on the form through its ControlToValidate property. Then, when the focus leaves the input control or the user clicks on a button whose CausesValidation property is set to True, the validator checks whether a value has been entered into the input control. If not, the message in the ErrorMessage property is displayed.

    When an error occurs, the Display property of the validation control determines how the message in the ErrorMessage property is displayed. When you use flow layout, Dynamic usually works the best for this property. If you use a validation summary control as explained in chapter 7, though, you can change this property to None.

    If you look at the aspx code in this figure, you can see how the properties are set for the two required field validators that are shown in the previous figure. The first one validates the text box named txtInterestRate. The second one validates the text box named txtYears. This aspx code will be added after the end tag for the table in the code in figure 2-11.

    How to use the range validator

    The range validator lets you set the valid range for an input value. To use this control, you set the properties in the first table in figure 2-13, plus the properties in the second table. In particular, you set the minimum and maximum values for an input value.

    For this control to work correctly, you must set the Type property to the type of data you’re testing for. Because the interest rate entry can have decimal positions, for example, the Type property for the first range validator is set to Double. In contrast, because the year entry should be a whole number, the Type property for the second range validator is set to Integer. You can see how all of the properties for the two range validators are set by reviewing the aspx code.

    Common validation control properties

    Property

    Description

    ControlToValidate

    The ID of the control to be validated.

    Display

    Determines how an error message is displayed. Specify Static to allocate space for the message in the page layout, Dynamic to have the space allocated when an error occurs, or None to display the errors in a validation summary control.

    ErrorMessage

    The message that’s displayed in the validation control when the validation fails.

    Additional properties of a range validator

    Property

    Description

    Maximum

    The maximum value that the control can contain.

    Minimum

    The minimum value that the control can contain.

    Type

    The data type to use for range checking (String, Integer, Double, Date, or Currency).

    The aspx code for the validation controlson the Future Value form

      <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"  
          ControlToValidate= "txtInterestRate" Display="Dynamic"
          ErrorMessage="Interest rate is required.">

      </asp:RequiredFieldValidator>

      <asp:RangeValidator ID="RangeValidator1" runat="server" 
          ControlToValidate= "txtInterestRate" Display="Dynamic"
          ErrorMessage="Interest rate must range from 1 to 20."
          MaximumValue="20" MinimumValue="1" Type="Double">

      </asp:RangeValidator><br />

      <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
          ControlToValidate="txtYears" Display="Dynamic"
          ErrorMessage="Number of years is required.">

      </asp:RequiredFieldValidator>

      <asp:RangeValidator ID="RangeValidator2" runat="server"
          ControlToValidate="txtYears" Display="Dynamic"
          ErrorMessage="Years must range from 1 to 45."
          MaximumValue="45" MinimumValue="1" Type="Integer">
      </asp:RangeValidator>

    Figure 2-13. How to use the required field and range validators

    Description

    1. The required field validator is typically used with text box controls, but can also be used with list controls.
    2. The range validator tests whether a user entry falls within a valid range.
    3. If the user doesn’t enter a value into the input control that a range validator is associated with, the range validation test passes. Because of that, you should also provide a required field validator if a value is required.

    More ASP.NET Articles
    More By Murach Publishing


       · This article is an excerpt from the book "Murach's ASP.NET 2.0 Web Programming with...
     

    Buy this book now. This article is excerpted from the book Murach's ASP.NET 2.0 Web Programming with VB2005, written by Doug Lowe (Murach, 2006; ISBN: 1890774324). Check it out today at your favorite bookstore. Buy this book now.

    ASP.NET ARTICLES

    - Developing a Mini ASP.NET AJAX Server Centri...
    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT