Today, we will mainly look at the usage of the validation controls in ASP. NET. As the name suggests, the verification control is used to verify the input format of the control on the page. To speed up the development of Asp.net websites, Microsoft provides a set of Asp.net verification controls.
ASP. NET supports the following verification controls
Requiredfieldvalidator (non-empty verification)
Make sure that the user does not skip the input control. The requiredfieldvalidator control can be bound with the text box to force users to enter the text box. Use the Selection control. For example, for the drop-down box control and single-choice button, requiredfieldvalidator ensures that the user selects to use it without using the specified default value. Requiredfieldvalidator does not check the validity of the data, but ensures that some data is input or selected.
Rangevalidator (range verification)
Make sure that the entered number is within the specified range. You can check the range between a number (greater than 10 and less than 100) and a character (between D and K ), or a range between dates (after 1/1/01 to before 2/28/01)
Comparevalidator (comparison verification)
Compare user input and other values. It can be compared with a specified time or the property value of another control. It can also be compared with the value in the database.
Regularexpressionvalidator (Regular Expression verification)
It is one of the most powerful verification controls. It can compare user input with the provided expressions. You can use this verification control to check valid social insurance numbers, phone numbers, and passwords.
This course mainly discusses verification controls. For more information about regular expressions, see related content.
Customvalidator (user-defined verification)
If there is no control that meets your needs, you can use the customvalidator control. It can check whether user input violates the information provided by the custom method.Algorithm.
Validationsummary (verification error display set)
The validationsummary control is used to display and verify the summary of all verification errors. When we set the display attribute of the verification control to none, the verification error message is displayed here.
The validationsummary control has three common attributes:
Attribute name |
Description |
Displaymode |
Specify the display mode. Three modes are available: bulletlist, list, And singleparagraph. |
Showmessagebox |
Whether to display the verification error summary in the client prompt box |
Showsummary |
Whether to Display Error summary in inline mode on the webpage |
Common property verification controls:
By focusing on the first invalid verification control, you can make the page more friendly. Therefore, you can add the setfocusonerror attribute for each verification control and set it to true (false by default)
Note:: When you click the submit button, the page is sent to the server. Each verification control is checked. If each control is valid, the isvalid attribute of the page returns true.
Because the usage of the verification control is searched online, we will not go into details.
Experience: The browser of the higher version supports DHTML and. Net authentication is completed on the client, which avoids the process of returning to the server for processing. In earlier browsers. TheseCodeThe Code has not changed, but must be sent to the client to ensure that the server is verified. Even after the client verification is complete, the value is finally verified on the server. This is also a safe method. If the control is invalid, server-side authentication is required. In this case, client verification adds the clienttarge attribute to the @ page command. <% @ Page
Clienttarget = "downlevel" %>. This command will result in verification on the server, even if the browser supports DHTML and client verification.
Sometimes, no verification is required, for example, when you click "cancel. Therefore, many Return spaces, such as imagebutton and linkbutton, all have a causevalidation attribute, which indicates whether to perform verification when a default event of the control is triggered. If the causevaliation attribute is set to true, that is, the default value, the page will not be returned when verification fails. However, if the causevalidation attribute is set to false, the user's return button on the page will not perform the verification process.
Display PropertiesIf it is set to static, ASP. NET is notified. no matter whether the information is displayed or not, the page space must be allocated to it. If this attribute is set to dynamic, no space is allocated until the error message is displayed. The dynamic allocation function is very powerful, but when the information is displayed, the control may jump to the page.
I am deeply ashamed that there is no corresponding code to explain this time. I will explain it in the future.