The RangeValidator Control

RangeValidator Control"-->

only for RuBoard

The RangeValidator Control

The RangeValidator control enables you to specify a range for the values entered into the input control. Such a range would be applicable if you have a B2B e-commerce site, and you wanted to set minimum and maximum order rates on some products. There are two ways to specify the minimum and maximum values. The first is to set the MinimumValue and Maximum Value to specified values. The second is to set the MinimumControl and MaximumControl values with the ID value of other HTML controls. As with the CompareValidator control, you can assign the range's data type with the Type attribute of the RangeValidator control.

Listing 9.7 contains an example using the RangeValidator . This is a very simple example that checks an integer value entered into a TextBox . If the value entered is at least one and not more than 100, it is considered valid.

Listing 9.7 Using the RangeValidator Control
 01: <html> 02:  <body style="font-size:10"> 03:  <form runat="server"> 04: 05:   <h3>RangeValidator</h3> 06: 07:   Pick a number between 1 and 100 08: 09:   <asp:TextBox 10:    runat="server" 11:    id="txtNumber" 12:   /> 13: 14:   <p> 15: 16:   <asp:RangeValidator 17:    runat="server" 18:    Type="Integer" 19:    ControlToValidate="txtNumber" 20:    MinimumValue="1" 21:    MaximumValue="100" 22:    ErrorMessage="You must enter a number between 1 and 100" 23:    Display="Dynamic" 24:   /> 25: 26:  <p> 27: 28:  <asp:Button id="SubmitButton" 29:      runat="server" 30:      Text="Submit" 31:   /> 32: 33:   </form> 34:  </body> 35: </html> 

Listing 9.7 uses the MinimumValue and MaximumValue attribute to determine what to compare to validate the TextBox value. The Type attribute is set to Integer , so only integers are accepted. In this example, the value of the TextBox must be at least 1 but not more than 100. Try entering a number less than 1 or greater than 100 and the page will not submit. Also try entering something other than an integer; again the page will not submit. Although, if nothing is entered, the page will submit because we are lacking a RequiredFieldValidator . Figure 9.4 contains the page after something other than an integer is entered as the value.

Figure 9.4. The page is invalid because my name was entered.
only for RuBoard

Programming Data-Driven Web Applications with ASP. NET
Programming Data-Driven Web Applications with ASP.NET
ISBN: 0672321068
EAN: 2147483647
Year: 2000
Pages: 170

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: