C#webfrom six verification and use method

Source: Internet
Author: User

C # contains six types of authentication methods, namely:

One, non-null verification requiredfieldvalidator.

Second, comparative verification CompareValidator.

Third, scope verification RangeValidator.

Four, the regular expression validation RegularExpressionValidator.

V. Verification summary ValidationSummary.

Vi. custom Validation.

Two application tips:


1. Prevent the button from firing the validation control.
By default, the Class 3 button fires validation.
If you do not want to fire validation: give the button a Causevalidation=false

2. Verify the problem with the grouping.
Set the ValidationGroup property of the input control (text box, radio, multiple selection), validation control (non-null, contrast, range, regular, custom, summary), button to the same value.

They become a group.

The first three attributes that need to be modified to use the validation space (six general authentication methods are common):

1.ErrorMessage: Error message displayed for validation failure

2.Display: How the Validator is displayed-in general dynamic display (verification failure display).

3.CotrolToValidate: The control ID to validate (for example: Verify the contents of the account in the TextBox, cotorltovalidate the textbox ID).

Different properties:

One, non-null verification requiredfieldvalidator.

InitialValue-The initial value of the validation, the value of the validated control is the same as this value, is considered null

For example: two characters (required) in the text box

Second, comparative verification CompareValidator.

ControlToCompare-The ID of the control to compare

ValueToCompare-the value to compare

Operator-Operator of contrast

Type-types of comparisons entered

Third, scope verification RangeValidator.

MaximumValue-Upper limit of range
MinimumValue-Lower limit of range
Type-Types

Four, the regular expression validation RegularExpressionValidator.

ValidationExpression-Validate expression (also definable)

V. Verification summary ValidationSummary.

ShowMessageBox-whether to display summary error messages as dialog boxes
ShowSummary-whether to display summary error messages on the page

Vi. custom validation.---Custom validation is considered to be the most powerful authentication method

Required Information:

ErrorMessage-Prompt message after verifying the error

ControlToValidate-ID of the control to validate

Display-how it is displayed. static-does not show up also occupies space. dynamic-does not show space

ClientValidationFunction-The function name of the client-side validation function. (Do not add brackets)

Specification for client-side validation functions:
Function name (event source, event data)
{
The event data. Value-values to be given to the certificate. The value in the input box to be validated by the validation control.
The event data. IsValid--tells the validation control to verify that it passed.
}

Case:

      <script language= "JavaScript" > Function Zhishu (A, b) {//a-event source, B-event data//main use B.value-gets the value of the control to be validated by the validation control.            The value that will be validated. B.isvalid-tells the browser to verify that it is passed.            true-through. false-does not pass (displays the errormessage, blocks the submission).            Step//1. Take out the values to be validated.            var s = b.value;            2. verify var IsOK = false;                 if (IsNaN (s) = = False) {//first to see is not a number var ZC = 0;     The number of the remainder is 0 var num = parseint (s);                    Converted to an integer calculation for (var i = 1; I <= num; i++) {//starting from 1 to the value itself, divisible by each, if divisible to record zc++;                    if (num% i = = 0) {zc++;                }} if (Zc = = 2) {IsOK = true;                } else {IsOK = false;            }} else {IsOK = false;            }//3. Tell the validation control whether validation passed. B.isvalid = IsOK;        } </script> 

C#webfrom six verification and use method

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.