ASP.Net validation controls validate
the user input data to ensure that useless, unauthenticated or contradictory
data don’t get stored.
ASP.Net provides the following
validation controls:
- RequiredFieldValidator
- RangeValidator
- CompareValidator
- RegularExpressionValidator
- CustomValidator
- ValidationSummary
- RequiredFieldValidator: The RequiredFieldValidator control ensures that the required field is not empty. It is generally tied to a text box to force input into the text box.
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="must enter name">
</asp:RequiredFieldValidator>
2. Range Validator:The RangeValidator control verifies that the input value falls within a predetermined range.
The syntax for the control:
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="TextBox4" ErrorMessage="not in range"
MaximumValue="12/12/12" MinimumValue="11/11/11" Type="Date"></asp:RangeValidator>
It has three specific properties:
Properties
|
Description
|
Type
|
it defines the type of the data;
the available values are: Currency, Date, Double, Integer and String
|
Minimum Value
|
it specifies the minimum value of
the range
|
Maximum Value
|
it specifies the maximum value of
the range
|
3. The Custom Validator:The CustomValidator control allows
writing application specific custom validation routines for both the client
side and the server side validation.
The client side validation is
accomplished through the ClientValidationFunction property. The client side
validation routine should be written in a scripting language, like JavaScript
or VBScript, which the browser can understand.
The server side validation routine
must be called from the control.s ServerValidate event handler. The server side
validation routine should be written in any .Net language, like C# or VB.Net.
The basic syntax for the control
<asp:CustomValidator ID="CustomValidator1"
runat="server"
ClientValidationFunction=.cvf_func.
ErrorMessage="CustomValidator">
</asp:CustomValidator>
|
0 comments:
Post a Comment