Validation - Controls
Validation - Controls
NET IT Department
5th Semester VALIDATION CONTROLS Krunal Prajapati
COMPARE VALIDATOR
The CompareValidator control allows you to compare the value entered by the user into
an input control, such as a TextBox control, with the value entered into another input
control, or with a constant value. You can also use the CompareValidator control to
determine whether the value entered into an input control can be converted to the data
type specified by the Type property.
PROPERTIES
PROPERTY DESCRIPTION
BackColor The background color of the CompareValidator control
ControlToCompare The name of the control to compare with
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
Equal
GreaterThan
GreaterThanEqual
LessThan
LessThanEqual
NotEqual
DataTypeCheck
runat Specifies that the control is a server control. Must be set to "server"
Text The message to display when validation fails
WEB PROG. USING ASP.NET
6th Semester VALIDATION CONTROLS Krunal Prajapati
Type Specifies the data type of the values to compare. The types are:
Currency
Date
Double
Integer
String
EXAMPLE
OUTPUT
Page 2 of 11
WEB PROG. USING ASP.NET
6th Semester VALIDATION CONTROLS Krunal Prajapati
CUSTOM VALIDATOR
The CustomValidator control allows you to create a validation control with customized
validation logic. For example, you can create a validation control that checks whether the
value entered into a text box is an even number.
PROPERTIES
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
Page 3 of 11
WEB PROG. USING ASP.NET
6th Semester VALIDATION CONTROLS Krunal Prajapati
EXAMPLE
VB CODE
OUTPUT
Page 4 of 11
WEB PROG. USING ASP.NET
6th Semester VALIDATION CONTROLS Krunal Prajapati
RANGE VALIDATOR
The RangeValidator control allows you to check whether a user's entry is between a
specified upper and lower boundary. You can check ranges within pairs of numbers,
alphabetic characters, and dates.
Note: If the input control is empty, no validation functions are called and validation
succeeds. Use a RequiredFieldValidator control to prevent the user from skipping an input
control.
PROPERTIES
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
EnableClientScript A Boolean value that specifies whether client-side validation is enabled or not
Enabled A Boolean value that specifies whether the validation control is enabled or not
ErrorMessage The 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
ForeColor The foreground color of the control
id A unique id for the control
IsValid A Boolean value that indicates whether the control specified by ControlToValidate
is determined to be valid
MaximumValue Specifies the maximum value of the input control
MinimumValue Specifies the minimum value of the input control
runat Specifies that the control is a server control. Must be set to "server"
Type Specifies the data type of the value to check. The types are:
Currency
Date
Double
Integer
String
Page 5 of 11
WEB PROG. USING ASP.NET
6th Semester VALIDATION CONTROLS Krunal Prajapati
EXAMPLE
OUTPUT
Page 6 of 11
WEB PROG. USING ASP.NET
6th Semester VALIDATION CONTROLS Krunal Prajapati
REGULAREXPRESSION VALIDATOR
Note: If the input control is empty, no validation functions are called and validation
succeeds. Use a RequiredFieldValidator control to prevent the user from skipping an input
control.
PROPERTIES
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
EnableClientScript A Boolean value that specifies whether client-side validation is enabled or not
Enabled A Boolean value that specifies whether the validation control is enabled or not
ErrorMessage The 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
ForeColor The foreground color of the control
id A unique id for the control
IsValid A Boolean value that indicates whether the control specified by
ControlToValidate is determined to be valid
runat Specifies that the control is a server control. Must be set to "server"
BackColor The background color of the RegularExpressionValidator control
Text The message to display when validation fails
ValidationExpression Specifies the expression used to validate input control. The expression validation
syntax is different on the client than on the server. JScript is used on the client.
On the server, the language you have specified is used
Page 7 of 11
WEB PROG. USING ASP.NET
6th Semester VALIDATION CONTROLS Krunal Prajapati
EXAMPLE
OUTPUT
REQUIREDFIELD VALIDATOR
Use the RequiredFieldValidator control to make an input control a mandatory field. The
input control fails validation if the value it contains does not change from its initial value
when validation is performed. This prevents the user from leaving the associated input
control unchanged. By default, the initial value is an empty string (""), which indicates that
a value must be entered in the input control for it to pass validation.
Note: Extra spaces at the beginning and end of the input value are removed before
validation is performed. This prevents a space being entered in the input control from
passing validation.
PROPERTIES
Page 8 of 11
WEB PROG. USING ASP.NET
6th Semester VALIDATION CONTROLS Krunal Prajapati
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
EnableClientScript A Boolean value that specifies whether client-side validation is enabled or not
Enabled A Boolean value that specifies whether the validation control is enabled or not
ErrorMessage The 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
ForeColor The foreground color of the control
id A unique id for the control
InitialValue Specifies the starting value of the input control. Default value is ""
IsValid A Boolean value that indicates whether the control specified by ControlToValidate
is determined to be valid
runat Specifies that the control is a server control. Must be set to "server"
Text The message to display when validation fails
EXAMPLE
OUTPUT
Page 9 of 11
WEB PROG. USING ASP.NET
6th Semester VALIDATION CONTROLS Krunal Prajapati
VALIDATION SUMMARY
The ValidationSummary control allows you to summarize the error messages from all
validation controls on a Web page in a single location. The summary can be displayed as a
list, a bulleted list, or a single paragraph, based on the value of the DisplayMode property.
The error message displayed in the ValidationSummary control for each validation control
on the page is specified by the ErrorMessage property of each validation control. If
the ErrorMessage property of the validation control is not set, no error message is
displayed in the ValidationSummary control for that validation control. You can also
specify a custom title in the heading section of the ValidationSummarycontrol by setting
the HeaderText property.
PROPERTIES
BulletList
List
SingleParagraph
EnableClientScript A Boolean value that specifies whether client-side validation is enabled or not
Enabled A Boolean value that specifies whether the validation control is enabled or not
ForeColor The fore color of the control
HeaderText A header in the ValidationSummary control
id A unique id for the control
runat Specifies that the control is a server control. Must be set to "server"
ShowMessageBox A Boolean value that specifies whether the summary should be displayed in a
message box or not
ShowSummary A Boolean value that specifies whether the ValidationSummary control should be
displayed or hidden
OUTPUT
Page 10 of 11
WEB PROG. USING ASP.NET
6th Semester VALIDATION CONTROLS Krunal Prajapati
EXAMPLE
Page 11 of 11