Home | HTML | Asp.Net | HTML Probe | .Net Probe
   
 www.solvingera.com 
  Contact Us |Sitemap
  
 

Web Server Validation Controls

  Skip Navigation LinksHome>Asp Home>Validation Controls

Validation is a process or set of rules that you apply to the data you collect. The data you collect comes from the Web forms which are made up of many different types of HTML elements, such as text boxes, radio buttons, check boxes, drop-down lists, and more. So validation is required to get filtered information. There are various situations where validation is required such as:tion. There are various situations where validation is required such as:
     ◊ Is minimum age 18 year ?
     ◊ Is something entered in the text box?
     ◊ Is the data entered in the text box in the form of an e-mail address?

There are six validation control in ASP.NET 3.5 which is used to validate the information by attaching to the input controls.
  • RequiredFieldValidator

  • CompareValidator

  • RangeValidator

  • RegularExpressionValidator

  • CustomValidator

  • ValidationSummary

The RequiredFieldValidator Server Control

The RequiredFieldValidator control simply check whether a server control, (like TextBox etc.) added to a Web Form, has a value or not. It is a simple validation control, but it is one of the most frequently used. You must have a RequiredFieldValidator control for each form element on which you wish to enforce a value-required rule.

Some important properties of the RequiredFieldValidator Server Control are:
  • ControlToValidate : Specify the ID of the control to be validated.

  • ErrorMessage : Specify the error message to be displayed when the validation condition fails.

  • Text: display the error message displayed by the control.
Control ExampleOutput
RequiredFieldValidator Control <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<
asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="Error Message: Write Something">
</
asp:RequiredFieldValidator>

Name :  
 


The CompareValidator Server Control

The CompareValidator control allows you to make comparisons between two controls value. The value can be a number or text.

Some important properties of the CompareValidator Server Control are:
  • ControlToCompare : Specifies the ID of the control that will be used to compare values.

  • ControlToValidate: Specify the ID of the control to be validated.

  • ErrorMessage : Sets the error message to be displayed when the validation condition fails.

  • ValueToCompare : Specifies the ID of the control to be compared.
Control ExampleOutput
CompareValidator Control

<asp:UpdatePanel ID="UpdatePanel2" runat="server">

<ContentTemplate>

Password:<asp:TextBox ID="TextBox4" runat="server" TextMode="Password"></asp:TextBox>

Re-Type Password:<asp:TextBox ID="TextBox5" runat="server" TextMode="Password"></asp:TextBox>

<asp:CompareValidator ID="CompareValidator2" runat="server" ControlToCompare="TextBox2" ControlToValidate="TextBox3" ErrorMessage="Error Message: Value Must Be Same."></asp:CompareValidator>

<asp:Button ID="Button3" runat="server" onclick="Button2_Click" Text="Check Validator" />

</ContentTemplate>
</
asp:UpdatePanel>
Password:

Re-Type Password:
 

The RangeValidator Server Control

The RangeValidator control makes sure that the end-user value or selection provided is between a specified range as opposed to being just greater than or less than a specified constant. The MinimumValue and MaximumValue properties can contain dates, number, currency, amounts, or strings.

Some important properties of the RangeValidator Server Control are:
  • ControlToValidate : Specify the ID of the control to be validated.

  • ErrorMessage : Sets the error message to be displayed when the validation condition fails.

  • MaximumValue: Sets the maximum Value.

  • MinimumValue: Specify the minimum value.
Control ExampleOutput
RangeValidator Control

<asp:UpdatePanel ID="UpdatePanel3" runat="server">

<ContentTemplate>

<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>

<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox4" ErrorMessage="Error Message: Starting Number Should be 1<=5" MaximumValue="5" MinimumValue="1">

</asp:RangeValidator>

<asp:Button ID="Button4" runat="server" Text="Check Validator"/>
</
ContentTemplate>

</
asp:UpdatePanel>
Enter Number :

 

The RegularExpressionValidator Server Control

The RegularExpressionValidator checks whether the user’s input based on a pattern that you define using a regular expression or not. This is a good control to use to check e-mail addresses, phone numbers or an Internet URL ; if it doesn’tmatch this definition, the page is considered invalid.

Some important properties of the RegularExpressionValidator Server Control are:
  • ControlToValidate : Specify the ID of the control to be validated.

  • ErrorMessage : Sets the error message to be displayed when the validation condition fails.

  • ValidationExpression : Sets the regular expression.
Control ExampleOutput
RegularExpressionValidator Control

<asp:UpdatePanel ID="UpdatePanel6" runat="server">

<ContentTemplate>

Enter E-mail Address : <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>

<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBox5" ErrorMessage="Error Message : Enter valid e-mail address" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>

<asp:Button ID="Button5" runat="server" Text="Check Validator" />

</ContentTemplate>
</
asp:UpdatePanel>
Enter E-mail Address :

 

The CustomValidator Server Control

The CustomValidator control allows you to build your own client-side or server-side validations that can then be easily applied to your Web forms. The CustomValidator Control is used to perform user define validations that cannot be performed by the standard validator provided by the ASP.NET.

Some important properties of the CustomValidator Server Control are:
  • ControlToValidate : Specify the ID of the control to be validated.

  • ErrorMessage : Sets the error message to be displayed when the validation condition fails.

  • ClientValidationNumber : Sets client-side script function.
Control ExampleOutput
CustomValidator Control

<asp:UpdatePanel ID="UpdatePanel6" runat="server">

<ContentTemplate>Enter Number : <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>

<asp:CustomValidator ID="CustomValidator2" runat="server" ClientValidationFunction="validateNumber" ControlToValidate="TextBox6" ErrorMessage="Error Message : Number must be divisible by 6"></asp:CustomValidator>

<asp:Button ID="Button6" runat="server" Text="Button" />

</ContentTemplate>
</
asp:UpdatePanel>
Enter Number :

 

The ValidationSummary Server Control

The ValidationSummary control is not a control that performs validations on the content input into your Web forms. Instead, this control is the reporting control, which is used to Displays all the error messages from the validators in one specific spot on the page specified by the user.

Some important properties of the ValidationSummary Server Control are:
  • HeadText : Sets the text to be displayed at the top of the summary.

  • ShowMessageBox : It displays the error message in a pop-up message box when the value of its property is True.
  • Show Summary : Enables or disables the summary of error message.
  
     
     
  
DMCA.com Protection Status
Design & Maintain By solvingera group| solvingera.com © 2013-2014 | all right reserved |Privacy Policy | Back to top