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"
>
Placeholder
</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 |
Yi |
Dinamic |
The verification error message is dynamically displayed. The location space on the page is provided only when the verification error occurs. |
None |
Verification error message, but not displayed on the page |
Static |
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">
<Div>
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>
</Div>
</Form>