| | | | | | | | | |
|
|
|
|
|
|
|
|
| |
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.
- Go to the Toolbox and under the Validation section, select RequiredFieldValidator.

ASP.NET RequiredFieldValidator Control
- Drag and drop it on to the Form area.
- The following is the code you get in the Source View.
<asp:requiredfieldvalidator runat="server" errormessage="RequiredFieldValidator"></asp:requiredfieldvalidator>
- 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] |
|
| |
|
|
| | |
|
|
|