By adding Requiredfieldvalidator Control and link it to the required control, you can specify a user in ASP. NET Information must be provided in specific controls on the webpage. For example, you can specify that you must enter the "name" text box before submitting the registration form.
If the verification is performed on the client, you can leave the required fields blank (or retain the default values) when using this page, but you must provide non-default values before submitting the page. However, after you enter a value in a field, you cannot clear the field (or restore it to the default value ). If this field is cleared, the user will immediately see the error message when leaving this field. In server-side verification, no check is performed before the page is submitted. Therefore, the user will only see the error message after the page is submitted.
Note: Verification of required items is often used in conjunction with other types of verification. You can use multiple verification controls for a user input field as needed.
1 , requiredfieldvalidator Add the control to the page and set the following attributes:
attribute |
description |
controltovalidate |
id . |
errormessage , text , display |
Some attributes are used to specify the text content and position of errors displayed when the user skips the control. |
2 In ASP. NET WebpageCodeTo check validity. The following example demonstrates Textbox Server Control . Aspx File.
<Asp: textbox id = "txtlastname" runat = "server"> </ASP: textbox>
<Asp: requiredfieldvalidator id = "requiredfieldvalidator1" runat = "server"
Controltovalidate = "txtlastname"
Errormessage = "last name is a required field ."
Forecolor = "red">
</ASP: requiredfieldvalidator>