ASP.NET Basics

HTML Basics
ASP.NET Web Server
Advanced HTML
Application Designing
Using Visual Studio
ASP.NET Standards
ASP.NET Styling
ASP.NET Navigation

ASP.NET Tips

ASP.NET Validation
HTML forms
CSS Styling
CSS Advanced
ASP.NET Features
ASP.NET Image Effects
Common mistakes
DB Design tips

Building Applications

Design Secure Apps
Build Secure Apps

5. ASP.NET RequiredFieldValidator Control

« Previous Chapter

Next Chapter »

ASP.NET RequiredFieldValidator control can be used to make a validation check to make sure an input control is a required field when developing a web application. ASP.NET RequiredFieldValidator control’s validation fails if the input value does not change from its initial value.

Note:

  • By default the initial value of the ASP.NET RequiredFieldValidator control is an empty string (“”).

  • Before validation begins any spaces before and after the input value are removed.

  • The InitialValue property does not set the default value for the input control but it shows the value that you do not want the user to enter in the input control.

The following is an ASP.NET tutorial how to add an ASP.NET RequiredFieldValidator Control in Visual Studio.

  1. Go to the Toolbox and under the Validation section, select RequiredFieldValidator.

ASP.NET RequiredFieldValidator Control
ASP.NET RequiredFieldValidator Control

  1. Drag and drop it on to the Form area.

  2. The following is the code you get in the Source View.

<asp:requiredfieldvalidator runat="server" errormessage="RequiredFieldValidator"></asp:requiredfieldvalidator>

  1. The following is shows an example use of the ASP.NET RequiredFieldValidator Control.

<form id="form1" runat="server">
<div>
Username: <asp:TextBox id="username" runat="server" />
<br />
Password: <asp:TextBox id="password" runat="server" />
<br /><br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="username" Text="The Username field is required" runat="server" />
</div>
</form>

Note:

  • Two texboxes controls and a button control named Submit was created.

  • One RequiredFieldValidator control was created

  • If the username textbox was left empty the validation text “The Username field is required” will be displayed by the RequiredFieldValidator Control.

In the next chapter you will learn some of the properties of the ASP.NET RequiredFieldValidator Control.

« Previous Chapter

Next Chapter »

Table of Contents

Chapter 1 - ASP.NET CompareValidator Control
        Chapter 1.1 - ASP.NET CompareValidator Control Properties
Chapter 2 - ASP.NET CustomValidator Control
        Chapter 2.1 - ASP.NET CustomValidator Control Properties
Chapter 3 - ASP.NET RangeValidator Control
        Chapter 3.1 - ASP.NET RangeValidator Control Properties
Chapter 4 - ASP.NET RegularExpressionValidator Control
        Chapter 4.1 - ASP.NET RegularExpressionValidator Control Properties
» Chapter 5 - ASP.NET RequiredFieldValidator Control
        Chapter 5.1 - ASP.NET RequiredFieldValidator Control Properties
Chapter 6 - ASP.NET ValidationSummary Control
        Chapter 6.1 - ASP.NET ValidationSummary Control Properties

[top]