Gautam Buddha Temple Varanasi,Varanasi - Buddhist Pilgrimage

Wednesday, September 1, 2010

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.  
 Example with code:  
 1.RequiredFieldValidation:It is simple validation control which checks data is entered or not.  
 <asp:textbox id="txtEmpName" runat="server"/>  
 <asp:RequiredFieldValidator id="rfvtxtbox" runat="server" ControlToValidate="txtEmpName"  
 ErrorMessage="* Please enter the employee name" Display="dynamic">*  
 2.RangeValidator:It checks to see if a control value is within a valid range or not.  
 <asp:textbox id="txtDOB" runat="server"/>  
 <asp:RangeValidator id="rangeVal" runat="server"  
 ErrorMessage="* Please enter the valid date" Display="static">*</asp:RangeValidator>  
 3.RegularExpressionValidator:It can be used for email validation or any specified string based on pattern matching.  
 E-mail: <asp:textbox id="txtEmail" runat="server"/>  
 <asp:RegularExpressionValidator id="revemail" runat="server"  
 ErrorMessage="* Please enter valid e-mail ."  
 4.CompareValidator: It allows you to make comparisons between two form controls and also compare values contained with  
 these controls to constants that specified by userd.  
 New Password: <asp:textbox id="txtNewPass" runat="server"/><br />  
 Confirm Passowrd: <asp:textbox id="txtConfirmPass" runat="server"/><br />  
 <asp:CompareValidator id="valCompare" runat="server"  
 ControlToValidate="txtNewPass" ControlToCompare="txtConfirmPass"  
 ErrorMessage="* New Password and confirm password are not same"  
 5.CustomValidator:It allows you to write your own server-side or client-side validations logic and it can be easily applied to your web forms controls.  
 <asp:CustomValidator ID="cv" runat="server"   
 ControlToValidate="txtName" ClientValidationFunction="customvalidationr"   
 ErrorMessage="Please enter correct name"></asp:CustomValidator>  
 <asp:TextBox ID="txtName" runat="server"></asp:TextBox>  
 <asp:Button ID="btnSubmit" runat="server" />  
 Client side javascript  
 <script type="text/javascript">  
 function customvalidation(oSrc,args)  
 write your code here  


  1. Very nice article. I really enjoyed it reading. And it also cleared lot of my doubts about Validation controls. Check this link too its also having post with wonderful explanation on Validation controls...

    Thanks Everyone!!

  2. nice articles,thankyou

  3. it's very useful.

  4. its really good thanks for posting

  5. good article.. which gives complete summary on validation controls..

  6. useful to us.. but need ex.. for client side validator

  7. its very nice and helpful tutorial.............thanks

  8. Hi..very nice tutorial keep it up dude

  9. Hi,

    This is very informative article. Thanks for sharing your knowledge. There are few links that also helpful for developers.

  10. Vice informative article regarding validation controls. Developers can also check the detailed article on this topic at

  11. Given so much information in it. its very useful .perfect explanation about Dot net framework.Thanks for your valuable information. dot net training in chennai velachery | dot net training institute in velachery

  12. It is really a great work and the way in which u r sharing the knowledge is excellent.Thanks for helping me to understand basic concepts. As a beginner in Dot Net programming your post help me a lot.Thanks for your informative article.. dot net training and placement in chennai | best dot net training in chennai