Social Icons

Thursday, 16 May 2013

Validation Example: How to use RequiredFiledValidator in Asp.Net

How to use RequiredFieldValidator in Asp.Net


In my previous articles i explained Overview of Asp.Net Validation Controls,WPF architecture,Three tier architecture in .net application etc. Now i will explain In detailed about RequiredFieldValidator Control in Asp.Net.


RequiredFieldValidator Control in Asp.Net

This validation Control is used to make a field as mandatory in the form. Without filling the form user can't submit the form. Use the RequiredFieldValiator control to make an input control a mandatory field. The input control fails validation if the value it contains does not change from its initial value when validation is performed. This prevents the user from leaving the associated input control unchanged. By default Initial value is an empty string (""), which indicates that a value must be entered in the input control for it to pass validation.

Important Properties:

ControlToValidate: To which control this validation needs to apply.
InitialValue: Initial value of the control to which validation fails if you can't change this value.
ErrorMessage: Message to be displayed in validation summary control.
Text: Message to display in control. 
Display: When should be the error message displayed either static or dynamic.

 To use it:

1. Add two label, textbox and button control to form.
2. Now add requiredfieldvalidator control and set the controltovalidate to textbox,initialvalue,text and display properties.

Code looks like below

Button Click Event Code:

Form Work Like this:
RequiredFieldValidator Example

Download Source Code: 





 I hope you got an idea on how to use RequiredFieldValidator control in
           I would love to take feedback from my blog visitors. Your valuable suggestions,questions,comments and further requirements about my posts or blog are always welcome.

Related Tutorials

No comments:

Post a Comment

Please Give your Valuable Suggestions,Questions and Comments to improve my blog.