Some Interesting Fact of Validation Control

Here I am going to explain some interesting factor on ASP.net Validation Control. As we all are aware of how many types of validation controls are there and what are their uses (if you don’t please refer my past post).
Validation Control
Description
RequiredFieldValidator
It require for control to be filled mandatory
CompareValidator
It is used to compare values from one input control to another control
Range Validator
It checks the values are in specified range. It supports string, int, double and date data type
RegularExpressionValidator
It is used to check the specified pattern used
CustomValidator
It is used to make your own validation and use it
ValidationSummary
It is used to display all validation error report in summary

Here is one sample of RequiredFieldValidator how we use it..
<asp:RequiredFieldValidator ID="rfvalidator" runat="server" Display="Static" ControlToValidate="txtName" ErrorMessage="Please enter your name"></asp:RequiredFieldValidator>
In the above code we have define RequiredFieldValidator for Name to be mandatory filled by users. We target the control by ControlToValidate property of the Validation control, ErrorMessage to be displayed to user and the major part of the control to be understand is Display which have three option Static, Dynamic and None.
By default we use Static option of Display property but we have never thought behind the rest two options how and why it should be used.
Static: When we use this option it renders the html property on the page as visibility (which takes place whether controls are visible or not)
Dynamic: When we use this option it renders the html property on the page as display (which takes place only when controls are visible)
None: When we use this option it is used with validation summary
I hope this much information will help you to understand the basics of Validations Controls.

Comments