You are on page 1of 9

22/11/2022, 06:24 ASP.

Net Web Form Required Field Validator - javatpoint


Home ASP.NET C# ADO.NET Java PHP HTML CSS JavaScript jQuery XML

https://www.javatpoint.com/asp-net-web-form-required-field-validator 1/9
22/11/2022, 06:24 ASP.Net Web Form Required Field Validator - javatpoint

ASP.NET RequiredFieldValidator Control


This validator is used to make an input control required. It will throw an error if user leaves input
control empty.

It is used to mandate form control required and restrict the user to provide data.

Note: It removes extra spaces from the beginning and end of the input value before validation is
performed.

The ControlToValidateproperty should be set with the ID of control to validate.

RequiredFieldValidator Properties

Property Description

AccessKey It is used to set keyboard shortcut for the control.

BackColor It is used to set background color of the control.

BorderColor It is used to set border color of the control.

Font It is used to set font for the control text.

ForeColor It is used to set color of the control text.

Text It is used to set text to be shown for the control.

ToolTip It displays the text when mouse is over the control.

Visible To set visibility of control on the form.

Height It is used to set height of the control.

Width It is used to set width of the control.

ErrorMessage It is used to set error message that display when validation fails.

ControlToValidate It takes ID of control to validate.

Example

https://www.javatpoint.com/asp-net-web-form-required-field-validator 2/9
22/11/2022, 06:24 ASP.Net Web Form Required Field Validator - javatpoint

Here, in the following example, we are explaining RequiredFieldValidator control and creating to
mandatory TextBox controls.

// RequiredFieldValidator.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RequiredFieldValidator.aspx.cs"
Inherits="asp.netexample.RequiredFieldValidator" %>  
<!DOCTYPE html>  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
<title></title>  
<style type="text/css">  
.auto-style1 {  
width: 100%;  
        }  
.auto-style2 {  
width: 165px;  
        }  
</style>  
</head>  
<body>  
<form id="form1" runat="server">  
<div>  
</div>  
<table class="auto-style1">  
<tr>  
<td class="auto-style2">User Name</td>  
<td>  
https://www.javatpoint.com/asp-net-web-form-required-field-validator 3/9
22/11/2022, 06:24 ASP.Net Web Form Required Field Validator - javatpoint

<asp:TextBox ID="username" runat="server"></asp:TextBox>  
<asp:RequiredFieldValidatorIDasp:RequiredFieldValidatorID="user" runat="server" ControlToValid
ErrorMessage="Please enter a user name" ForeColor="Red"></asp:RequiredFieldValidator>  
</td>  
</tr>  
<tr>  
<td class="auto-style2">Password</td>  
<td>  
<asp:TextBox ID="password" runat="server"></asp:TextBox>  
<asp:RequiredFieldValidator ID="pass" runat="server" ControlToValidate="password" ErrorMessa
ForeColor="Red"></asp:RequiredFieldValidator>  
</td>  
</tr>  
<tr>  
<td class="auto-style2"> </td>  
<td>  
<br/>  
<asp:Button ID="Button1" runat="server" Text="login"/>  
</td>  
</tr>  
</table>  
</form>  
</body>  
</html>  

Output:

It produces the following output when view in the browser.

https://www.javatpoint.com/asp-net-web-form-required-field-validator 4/9
22/11/2022, 06:24 ASP.Net Web Form Required Field Validator - javatpoint

It throws error messages when user login with empty controls.

← Prev
Next →

Youtube
For Videos Join Our Youtube Channel: Join Now

Feedback

Send your Feedback to feedback@javatpoint.com

Help Others, Please Share

https://www.javatpoint.com/asp-net-web-form-required-field-validator 5/9
22/11/2022, 06:24 ASP.Net Web Form Required Field Validator - javatpoint

Learn Latest Tutorials

Splunk tutorial SPSS tutorial Swagger T-SQL tutorial


tutorial
Splunk SPSS Transact-SQL
Swagger

Tumblr tutorial React tutorial Regex tutorial Reinforcement


learning tutorial
Tumblr ReactJS Regex
Reinforcement
Learning

R Programming RxJS tutorial React Native Python Design


tutorial tutorial Patterns
RxJS
R Programming React Native Python Design
Patterns

Python Pillow Python Turtle Keras tutorial


tutorial tutorial
Keras
Python Pillow Python Turtle

Preparation

Aptitude Logical Verbal Ability Interview


Reasoning Questions
Aptitude Verbal Ability
Reasoning Interview Questions
https://www.javatpoint.com/asp-net-web-form-required-field-validator 6/9
22/11/2022, 06:24 ASP.Net Web Form Required Field Validator - javatpoint

Company
Interview
Questions
Company Questions

Trending Technologies

Artificial AWS Tutorial Selenium Cloud


Intelligence tutorial Computing
AWS
Tutorial tutorial
Selenium
Artificial Cloud Computing
Intelligence

Hadoop tutorial ReactJS Data Science Angular 7


Tutorial Tutorial Tutorial
Hadoop
ReactJS Data Science Angular 7

Blockchain Git Tutorial Machine DevOps


Tutorial Learning Tutorial Tutorial
Git
Blockchain Machine Learning DevOps

B.Tech / MCA

https://www.javatpoint.com/asp-net-web-form-required-field-validator 7/9
22/11/2022, 06:24 ASP.Net Web Form Required Field Validator - javatpoint

DBMS tutorial Data Structures DAA tutorial Operating


tutorial System tutorial
DBMS DAA
Data Structures Operating System

Computer Compiler Computer Discrete


Network tutorial Design tutorial Organization and Mathematics
Architecture Tutorial
Computer Network Compiler Design
Computer Discrete
Organization Mathematics

Ethical Hacking Computer Software html tutorial


Tutorial Graphics Tutorial Engineering
Web Technology
Tutorial
Ethical Hacking Computer Graphics
Software
Engineering

Cyber Security Automata C Language C++ tutorial


tutorial Tutorial tutorial
C++
Cyber Security Automata C Programming

Java tutorial .Net Python tutorial List of


Framework Programs
Java Python
tutorial
Programs
.Net

Control Data Mining Data


Systems tutorial Tutorial Warehouse
Tutorial
Control System Data Mining
Data Warehouse

https://www.javatpoint.com/asp-net-web-form-required-field-validator 8/9
22/11/2022, 06:24 ASP.Net Web Form Required Field Validator - javatpoint

https://www.javatpoint.com/asp-net-web-form-required-field-validator 9/9

You might also like