ASP. NET required field verification control requiredfieldvalidator

Source: Internet
Author: User

Required field verification control requiredfieldvalidator: it is used to restrict empty fields and cannot be empty before submission on the page. You can find this control in the "verify" column in the toolbox.

The standard code used by the requiredfieldvalidator control is as follows:

<Asp: requiredfieldvalidator id = "validator_name" runat = "server"
Controltovalidate = "Name of the control to be checked"
Errormessage = "error message"
Display = "static | dymatic | none"
</ASP: requiredfieldvalidator>

Common attributes of the requiredfieldvalidator control:

1. controltovalidate: This attribute specifies the control to be verified. When setting this attribute, you can select any control in the form as the verification object from the drop-down menu;

2. errormessage: indicates the error message on the validatorsummary control when verification fails. Some verification messages are also displayed on the requiredfieldvalidator control. If the requiredfieldvalidator control has set the text attribute, when verification fails, the message specified by text is displayed, instead of the message specified by errormessage.

3. display: Display Mode of the error message; display, which has three possible values: None, static, and dinamic;


Display attribute values and their meanings

Property Value



The verification error message is dynamically displayed. The location space on the page is provided only when the verification error occurs.


Verification error message, but not displayed on the page


Unlike dinamic, this attribute allows the page to set aside space for displaying error information regardless of whether a verification error occurs.


Placeholder: indicates that when the display is static, the error information occupies the page space as large as the "Placeholder.


When the attribute value is dinamic, the verification error message is provided dynamically. Therefore, if the space is occupied by other page content, the display position of this part of content changes, which may make the page layout not as expected. Therefore, when selecting attribute values, we should make full use of space and make full use of the advantages of these three values on the basis of both layout and layout.

Requiredfieldvalidator control application instance: Verify the username field.

Page code:

<Form ID = "form1" runat = "server">

Enter the User name: <asp: textbox id = "textbox1" runat = "server"> </ASP: textbox>
* <Br/>
<Asp: button id = "button1" runat = "server" text = "Submit"/>
<Asp: requiredfieldvalidator id = "requiredfieldvalidator2" runat = "server"
Controltovalidate = "textbox1"
Errormessage = "requiredfieldvalidator"> you must enter the username </ASP: requiredfieldvalidator>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.