Saturday, 22 March 2014

Validation controls in

There are main 6 types of validation control; it used to validate the data inserted into input controls, it validates in client side itself and find and validate it. The validation is based on scenario;
Its contains:
1.       Required Field Validation in ASP.Net – It Checks, does the control have any value. It’s used when you want the control should not be empty. It ensures that the user does not skip a mandatory entry field.
Mandatory check of control in c#

  <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtValue" ErrorMessage="mandatory field"></asp:RequiredFieldValidator>

2.        Range Validation in ASP.Net : - Check that the value in the validated control has specific defined range. user's input is in a given range(Number or Character).e.g. TxtMobilevalue should not be more than 10 charatcter.
Date range validation in range control;

<asp:RangeValidator ID="RangeValidator1" ControlToValidate="txtValue" MinimumValue="2013-01-01" MaximumValue="2013-12-31" Type="Date" EnableClientScript="false"
Text="The date must be between 2013-01-01 and 2013-12-31!" runat="server" />

3.       Compare Validation in ASP.Net :  Check the value in the control should match the value in other control. It compares one controls value with other control value, constants and data type using a comparison operator (equals, greater than, less than, and so on). [e.g. comparing the password value of two textbox)
Password compare validator in

<asp:CompareValidator id="compval" Display="dynamic" ControlToValidate="txt1" ControlToCompare="txt2" ForeColor="red" BackColor="yellow" Type="String"
EnableClientScript="false" Text="Validation Failed!" runat="server" />
4.       Regular Expression validation in ASP.Net : When we want the control value should match the specific regular expression. The user's entry matches a pattern defined by a regular expression.  [e.g Email validation”

Email validation in
<asp:RegularExpressionValidator ID="regexEmailValid" runat="server" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="txtEmailAddress" ErrorMessage="Invalid Email!!"></asp:RegularExpressionValidator>

5.       Custom Validation in ASP.Net: It generally used for user defined validation. It’s using the using custom-coded validation logic.
<asp:CustomValidator ID="CustomValidator1" ControlToValidate="txt1" OnServerValidate="user" Text="Mobile number start with 9,8,7 and 10 length "

6 Validation Summary in ASP.Net:  Showing all the error in one place it display in alert message format or summary as alert format.
Summary of error message
<asp:ValidationSummary ID="ValidationSummary1" HeaderText="- You must validate folowing field" DisplayMode="BulletList"
EnableClientScript="true" runat="server"/>

No comments:

Post a Comment