Tuesday 11 March 2014

RangeValidator in ASP.NET

In this article I will explain what RangeValidator in ASP.NET is and what are the syntax and properties.

The RangeValidator does exactly what the name implies; it makes sure that the user input is within a specified range. You can use it to validate both numbers, strings and dates, which can make it useful in a bunch of cases. Since we validated numbers the last time, we will try with a date this time.

Syntax:

<asp:RangeValidator />

Properties:

ControlToValidate: The id of the control to validate

Display: The 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

MaximumValue : Specifies the maximum value of the input control

MinimumValue: Specifies the minimum value of the input control

Type: Specifies the data type of the value to check. The types are:
  • Currency
  • Date
  • Double
  • Integer
  • String
Example :

<asp:TextBox runat="server" id="txtDate" />
<asp:RangeValidator runat="server" id="rngDate" controltovalidate="txtDate" type="Date" minimumvalue="01-01-2014" maximumvalue="31-12-2016" errormessage="Please enter a valid date within 2016!" />



No comments:

Post a Comment