ASP. NET prerequisites (4) -- Web server verification controls

Source: Internet
Author: User

1. What is a verification control? If you want to input data of the correct type, you must check the input value, range, or format to verify that the user input meets the requirements. 2. Where is the verification control in. NET? In the validation Group of the Toolbox. 3. What are common ASP. NET controls? What are the differences? 1) CompareValidator control: Compared with the given value. 2) CustomValidator control: You can customize the verification logic. 3) RangeValidator control: checks whether the value of the control is within the specified valid range. 4) RegularExpressValidator control: Use a regular expression to verify that the data entered by the user conforms to the predefined format. 5) RequiredFieldValidator control: prevents users from entering null values. 6) ValidationSummary control: summarizes error messages of all verification controls on the web page. Tracing: All verification controls are inherited from the BaseValidator class, providing some public attributes for the verification control: member Description: ControlToValidator needs to verify whether the idcode of the input control EnableClientScript allows client verification (using js to Write Functions) enabled whether server-side verification ErrorMessage error message IsValid determines whether the value of the input control has passed verification 4 how to use ASP. net verification control? You can enable user input verification just like adding other server controls. Assign the ID number of the control to be associated with in the ControlToValidator attribute of the control. Client verification? Server verification? Client verification is intended for the user experience and prevents people from entering the correct information many times, such as some validity checks, such as string length, illegal characters, regular expressions, and non-empty characters. Mostly friendly tips (unreliable in nature, but fast response .) Real authentication is required to verify the business logic and security of the server. For example, if the password is correct, you need to write code in the background to check whether you have the permission or not. Place the data to be submitted and saved to the server for verification. (For the sake of security, the client authenticates, and the server also verifies .) Hybrid verification: both the client and server must be verified. DEMO: here we will talk about the client verification and server verification methods. Take the CustomValidator control as an example to verify whether the user entered an even number of clients for verification: here the JavaScrip code is used: <script language = "javascript" type = "text/javascript">/* verify whether the function is an even number */function ClientValidate (source, args) {if (args. value % 2) = 0) args. isValid = true; else args. isValid = false ;}</script> client verification control code: <asp: CustomValidator ID = "CustomValidator1" runat = "server" ControlToValidate = "txtOS" ErrorMessage = "not an even number! "ClientValidationFunction =" ClientValidate "> </asp: CustomValidator> server verification, C # code: public partial class _ Default: System. web. UI. page {// The server verifies whether the input is an even number. Protected void cvInput_ServerValidate (object source, ServerValidateEventArgs args) {// obtain the input value of the verification control. Int value = int. Parse (args. Value); // checks whether the value is an even number. If (value % 2) = 0) {args. isValid = true;} else {args. isValid = false ;}} server verification, control code: <asp: CustomValidator ID = "cvInput" runat = "server" ControlToValidate = "txtOS" ErrorMessage = "not an even number! "OnServerValidate =" ServerValidate "> </asp: CustomValidator> the final result is as follows:
Compared with CS controls, CS controls do not have verification controls.

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: info-contact@alibabacloud.com 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.