The use of the Range Validator is used to validate whether the specified data is in the middle of the specified range or not.
Following are main properties of the validation control.
MinimumValue | Gets or sets the minimum value of the range. | ||
MaximumValue | Gets or sets the maximum value of the range. | ||
Type | Integer/String/Date/Currency/Double. Used to specify the data type to validate. | ||
ControlToValidate | Gets or sets the input control to validate (eg. The ID value of asp:TextBox control). | ||
Display | dynamic static. Indicates how the area of error messages will be allocated. | Dynamic: The error message area will only be assigned when the error is displayed. Fixed: The error message area will be allocated in any case. | |
Enabled | true/false. Gets or sets whether to enable the validation control or not. | ||
ErrorMessage | Gets or sets the text of the error message that will be displayed when validation fails (This is displayed when ValidationSummary validatoin control is used.). | ||
Text | Gets or sets the description of the error message text. | ||
ValidationGroup | Gets or sets the validation group it belongs to. This is used to group a set of controls. | ||
SetFocusOnError | true/false. Used to move focus on the control that fails the validation. |
Example -
<asp:Label ID="lbl" AssociatedControlID="TextBox1" runat="Server" Text="Write into TextBox"></asp:Label>
<asp:TextBox ID="TextBox1" runat="Server"></asp:TextBox>
<asp:RequiredFieldValidator ID="req1" runat="Server" ControlToValidate="TextBox1" ErrorMessage="TextBox is Mandatory field" Text="Please write something in the Box."></asp:RequiredFieldValidator>
<asp:RangeValidator ID="range1" runat="Server" ControlToValidate="TextBox1" MinimumValue="5" MaximumValue="10" Display="dynamic" Type="Integer" Text="Integer only" ErrorMessage="Value must be between 5 to 10"></asp:RangeValidator>
<asp:Button ID="btnSubmit" runat="Server" OnClick="ChangeLabelText" Text="Change Label Text" />
<asp:ValidationSummary ID="ValidationSummary" runat="Server" ShowMessageBox="true" />
0 comments:
Post a Comment