The RequiredFieldValidator control is used to make an input control a required field. With this control, the validation fails if the input value does not change from its initial value. By default, the initial value is an empty string ("").

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






The background color of the RequiredFieldValidator control


The id of the control to validate

Error Message

The text to display in the page when validation fails.


The foreground color of the control


A unique id for the control

Initial Value

Specifies the starting value of the input control. Default value is ""


A Boolean value that indicates whether the control specified by ControlToValidate is determined to be valid


Specifies that the control is a server control. Must be set to "server"



<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

When we enter value in TextBox then page will execute

RequiredFieldValidator Control in ASP.Net


  Modified On Mar-22-2018 07:25:16 AM

Leave Comment