How to use RequiredFieldValidator in Asp.Net
Introduction:
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.
Description:
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:
Conclusion:
I hope you got an idea on how to use RequiredFieldValidator control in asp.net.
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
- Architecture of WPF.
- Creation of Three Tier Architecture in .Net Application.
- Difference between App.config and Web.Config
- Asp.Net Validation Controls Tutorial
- Asp.Net Ajax Tutorials
- Difference between Machine.Config and Web.Config in Asp.Net Framework.
- Basic Drawings and Shapes in WPF.
- How to read and write key values from and to App.config Settings file .Net Windows Application.
- How to Use RangeValidator Control in Asp.Net with Example.
- Asp.Net Ajax Server Controls, Ajax Control Toolkit Download and Installation Tutorial.
- How to Use ViewState in Asp.Net(State Management Techniques).
- How to use Hidden Field in Asp.Net with Example(State Managemet Techniques).
- Beginners Tutorial on How to use QueryStrings in Asp.Net(State Management Techniques).
- Asp.Net Cookie Usage Overview with example(State Management Techniques).
- Access Specifiers or Modifiers in C# with example(Oops Concept).
No comments:
Post a Comment
Please Give your Valuable Suggestions,Questions and Comments to improve my blog.