ASP.NET Validation Controls

Santosh0683
Posted by Santosh0683 under ASP.NET category on | Views : 1880
ASP.NET Validation Controls with example
Learning Technique for freshers : R3C2
1.RequiredFieldValidation Control
2.RangeValidator Control
3.RegularExpressionValidator Control
4.CompareValidator Control
5.CustomValidator Control

Properties of Validation Controls.
ControlToValidate - Id of control Which you want to validate.
ErrorMessage - Message that will be displayed in the validation summary.
IsValid - Whether or not the control is valid.
Validate - Method to validate the input control and update the IsValid property.
Display - How the error message will display.options are given below
None:Message is never displayed.
Static:Validation message will display in the page layout.
Dynamic:Validation message is dynamically added to the page if validation fails.

RequiredFieldValidator:

<asp:RequiredFieldValidator id="frvtxtName" runat="server" 
controlToValidate="txtEmpName"
errorMessage="Entered Name" display="static">
</asp:RequiredFieldValidator>

RegularExpressionValidator:
<asp:RegularExpressionValidator id="rev"
runat="server" display="static" controlToValidate="txtHour"
errorMessage="Enter 1-3 digits "
validationExpression="\d{1,3}">
</asp:RegularExpressionValidator>


CompareValidator:
<asp:CompareValidator id="cv" runat="server" display="static"
controlToValidate="txtNo" errorMessage="No must be numeric"
type="Double" operator="DataTypeCheck"></asp:CompareValidator>

RangeValidator:
<asp:RangeValidator id="rv" runat="server"
display="static" controlToValidate="txtDependents"
errorMessage="Enter 0 to 10"
type="Integer" minimumValue=0 maximumValue=10>
</asp:RangeValidator>

CustomValidator:
<asp:CustomValidator id="cv" runat="server"
display="static" controlToValidate="txtDeptNo"
onServerValidate="validateDeptNum"
errorMessage="Enter multiples of 10" >
</asp:CustomValidator>

Comments or Responses

Login to post response