---
title: "RequiredFieldValidator Control in ASP.Net"  
description: "The RequiredFieldValidator control is used to make an input control a required field. With this control, the validation fails if the input value does"  
author: "Pushpendra Singh"  
published: 2010-11-09  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/195/requiredfieldvalidator-control-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# RequiredFieldValidator Control in ASP.Net

The RequiredFieldValidator control is used to make an input control a [required](https://yourviews.mindstick.com/view/81031/vigilence-required-during-corona-pandemic) field. With this control, the [validation fails](https://www.mindstick.com/forum/34291/how-to-raise-a-callback-when-asp-dot-net-mvc-client-validation-fails) if the input value does not change from its initial value. By default, the initial value is an [empty string](https://www.mindstick.com/forum/12697/json-stringify-is-sending-empty-string) ("").\

```
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
```

**[Properties](https://yourviews.mindstick.com/view/81845/now-it-s-possible-to-predict-properties-of-any-molecule):**

| Property | Description |
| --- | --- |
| BackColor | The [background color](https://www.mindstick.com/forum/18/split-background-color) of the RequiredFieldValidator control |
| ControlToValidate | The id of the control to validate |
| [Error Message](https://www.mindstick.com/forum/23174/error-message-the-page-you-are-requesting-cannot-be-served-because-of-the-extension-configuration) | The text to display in the page when validation fails. |
| ForeColor | The foreground color of the control |
| id | A [unique id](https://www.mindstick.com/forum/23131/windows-phone-8-1-device-unique-id) for the control |
| Initial Value | Specifies the starting value of the input control. [Default value](https://www.mindstick.com/forum/23023/default-value-when-using-singleordefault) is "" |
| IsValid | A Boolean value that indicates whether the control specified by ControlToValidate is determined to be valid |
| runat | Specifies that the control is a server control. Must be set to "server" |

## Code:

```
  <asp:Label ID="Label2" runat="server" Text="Name"></asp:Label>  <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>       <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"         ErrorMessage="Enter your Name"></asp:RequiredFieldValidator>       <asp:Label ID="Label3" runat="server" Text="ID"></asp:Label>     <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>       <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2"         ErrorMessage="Enter your ID"></asp:RequiredFieldValidator>       <asp:Button ID="Button1" runat="server" Text="Save" OnClick="Button1_Click" />     <asp:Label ID="Label1" runat="server"></asp:Label>    protected void Button1_Click(object sender, EventArgs e)    {                   Label1.Text = " form is valid!";            }  
```

When we will not enter any value in the TextBox and when we will click save button then error message will be display.

![RequiredFieldValidator Control in ASP.Net](https://www.mindstick.com/mindstickarticle/34e5fb73-9bdf-4850-9a3e-e10a5f428148/images/0b71ab2e-f26f-45f1-a0fa-b828d58adf56.png)

When we enter value in TextBox then page will execute

![RequiredFieldValidator Control in ASP.Net](https://www.mindstick.com/mindstickarticle/34e5fb73-9bdf-4850-9a3e-e10a5f428148/images/93b7eca5-86de-4bc6-b93f-64a072117d9a.png)

---

Original Source: https://www.mindstick.com/articles/195/requiredfieldvalidator-control-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
