How to use RequiredFieldValidator Control in ASP.Net

In this article i will explain how to use RequiredFieldValidator control in ASP.Net.

RequirefieldVaidator control Checks that the validated control must contains a value. It cannot be empty.

The RequiredFieldValidator Control simply checks to see if something was entered into the HTML form element.

Here, is an example for understand RequiredFielValidator control.

First drag the RequiredFielValidator control on asp.net web form

Design ASP.Net web form with two textbox control along with two requiedfield validator control for each.

validation control in asp.net

How to user RequiedFielValidator control in ASP.Net

Here is output of our design, we have two Requiredfield validaor one for textbox name and other for textbox city.

The asp.net design HTML code is:

How to user RequiedFielValidator control in ASP.Net

How to user RequiedFielValidator control in ASP.Net

Now, go to  the Requiredfieldvalidator control property and set ErrorMessage and ControlToValidate property.

ErrorMessage display automatically the error message when our textbox will be blank.

validation control in asp.net

How to user RequiedFielValidator control in ASP.Net

Set the ControlToValidate property for identify the validated textbox.

validation control in asp.net

How to user RequiedFielValidator control in ASP.Net

In below screen if both textbox name and textbox city will be blank then both validator control show the ErrorMessage when we click the butoon control.

 

Here we have enter some value in textbox name and textbox city is blank, then validator control shows the error message for textbox city enter city !!.

How to user RequiedFielValidator control in ASP.Net

How to user RequiedFielValidator control in ASP.Net

How to user RequiedFielValidator control in ASP.Net

How to user RequiedFielValidator control in ASP.Net

 

Leave a Reply

Your email address will not be published. Required fields are marked *

7 + 6 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">