-->

Thursday, June 27, 2013

How to use RequiredFieldValidator Control in ASP.NET

How to use RequiredFieldValidator Control in ASP.NET

Introduction

The Required FieldValidator control is the simplest control , and is used to ensure that the user has entered the data into the input control, such as TextBox to which it is bound. For example , if you are entering data, for buying a T-shirt , in an input control , it is necessary to enter the size of the T-Shirt that you want to buy. If you do not enter a value , the validation control displays an error message .

Public property of the RequiredFieldValidator Class

initialValue : Handles the initial value of the associated input control.

Example



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="requiredfield.aspx.cs" Inherits="requiredfield" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>






UserName :
 
 
<asp:TextBox ID="usrtxt" runat="server"></asp:TextBox>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="usrtxt" ForeColor="Maroon">Field is required</asp:RequiredFieldValidator>

<br />

<asp:Button ID="Button1" runat="server" Text="Submit" />





 
 
</div>

</form>

</body>

</html>

 
Output
validator
 

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved