Page 78 - DCAP312_WEB_TECHNOLOGIES_II
P. 78

Web Technologies-II



                   Notes            •  Greater Than
                                    •  GreaterThanEqual

                                    •  LessThan
                                    •  LessThanEqual

                                    •  DataTypeCheck
                                 The Range Validator Control

                                 The RangeValidator server control is analogous to the CompareValidator server control, but the
                                 RangeValidator server control compares what is entered into the form field with two values and
                                 makes sure that what was entered by the client is between these two specified values.

                                 For instance, imagine that we have a text box where we want end users to enter their ages.
                                 Instead of being greater than or less than a specific constant, we want the values entered to be
                                 between a specific ranges of numbers. For this, we use the RangeValidator server control, as
                                 illustrated in example.

                                                Using the Range Validator Server Control to Work with a Range of Numbers
                                                Age:
                                                <asp:TextBox id= “TextBox1” runat= “server”></asp:TextBox>
                                                 
                                                <asp:RangeValidator id= “RangeValidator1” runat= “server”
                                                ControlToValidate= “TextBox1” Type= “Integer”
                                                 ErrorMessage= “You must be between 30 and 40”
                                                 MaximumValue= “40” MinimumValue= “30”></asp:RangeValidator>
                                                In this case, the user should enter a value between 30 and 40 in the text box.
                                                If some number is entered that is outside of this range, the RangeValidator
                                                server  control  fires  an  error  message  and  considers  the  form  submission
                                                invalid.
                                                The Type property enables us to create comparisons against many changed
                                                .NET Framework types, such as String, Integer, Double, Date, and Currency.
                                                These choices allow us to do a number of range comparisons. For instance, we
                                                can use the Currency value in the Type property to retrieve monetary-value
                                                entries that are within a certain range. We can also use the Date value for the
                                                Type property to make sure that the entry is between specific date ranges.
                                                Also, just as we can use the String data type in the CompareValidator server
                                                control, we can use the String data type with the RangeValidator server control
                                                to make sure that the value entered falls within a specific range of characters.
                                                For example, if the user is entering her last name, and we want only people
                                                with last names starting with M and P to proceed, we can easily do this by
                                                using the RangeValidator server control, as illustrated in Example.


                                                Comparing an Entry to a Range of Characters
                                                Last name:
                                                <asp:TextBox id= “TextBox1” runat= “server”></asp:TextBox>
                                                 


        72                                LOVELY PROFESSIONAL UNIVERSITY
   73   74   75   76   77   78   79   80   81   82   83