Range Validation Control in Asp.Net C#

RANGE VALIDATION

The RangeValidator control verifies that the input value falls within a predetermined range.
The RangeValidator control is used to check that the user enters an input value that falls between two values. It is possible to check ranges within numbers, dates, and characters.




DEMO


Html Coding 


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
        <tr><td>
            <asp:Label ID="Label1" runat="server" Text="Password"></asp:Label>
            </td><td>
                <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
                <asp:RangeValidator ID="RangeValidator1"
 runat="server"
                    ControlToValidate="txtPassword"
ErrorMessage="Valid Range Only 5-10"
                    MaximumValue="10" MinimumValue="05"></asp:RangeValidator>
            </td></tr>
        <tr><td colspan="2">
            <asp:Button ID="Button1" runat="server" Text="Save" />
            </td></tr>

    </table>
    </div>
    </form>
</body>



</html>



Main Properties are


PropertiesDescription
Typeit defines the type of the data; the available values are: Currency, Date, Double, Integer and String
MinimumValueit specifies the minimum value of the range
MaximumValueit specifies the maximum value of the range


Properties 




PropertyDescription
BackColorThe background color of the RangeValidator control
ControlToValidateThe id of the control to validate
DisplayThe display behavior for the validation control. Legal values are:
  • None (the control is not displayed. Used to show the error message only in the ValidationSummary control)
  • Static (the control displays an error message if validation fails. Space is reserved on the page for the message even if the input passes validation.
  • Dynamic (the control displays an error message if validation fails. Space is not reserved on the page for the message if the input passes validation
EnableClientScriptA Boolean value that specifies whether client-side validation is enabled or not
EnabledA Boolean value that specifies whether the validation control is enabled or not
ErrorMessageThe text to display in the ValidationSummary control when validation fails. Note:This text will also be displayed in the validation control if the Text property is not set
ForeColorThe foreground color of the control
idA unique id for the control
IsValidA Boolean value that indicates whether the control specified by ControlToValidate is determined to be valid


runatSpecifies that the control is a server control. Must be set to "server"


TextThe message to display when validation fails




First  - Add New Webform - select  Label & Textbox  & Button  From ToolBox.


Select - Range Validator  from Validation Tool - Select F4 Property Window - Control to Validate=txtPassword & Error Message required & Minimum Values & Maximum Values enter ( using Zero in front 06,07,08)











Next - F5 Click -  Run the Program 


Enter out of Range Values Show the Error Message







Enter the valid Range -  Hide the Error Message







0 comments:

Post a Comment