ASP. NET verification control

Source: Internet
Author: User

1. RequiredFieldValidator (verify the illegal value control) the control's English face is translated into a "non-empty control" and has a very important attribute: ControlToValidate, used to set whether the property value of the verified control is null (for TextBox, the property value is "Text "), therefore, you only need to select the control to be bound in ControlValidate (such as the TextBox ID of the "Login Name. If gender verification is a drop-down box (not selected by default), this control can also be verified using RequiredFieldValidate (the drop-down box has two attributes: "TextField" and "ValueField ", the former is used to display the value on the page. After a value is selected, the real value can be obtained through ValueField ). If you use RequiredFieldValidate to verify the drop-down box, it verifies its ValueField value. In this case, you must set another InitialValue. This attribute indicates that if the value of the verified control is equal to the value in InitialValue, it will be regarded as an invalid value. Conclusion 1: in fact, the criterion for determining the invalid value of RequiredFieldValidate is to compare whether the value of the compared control is consistent with that of InitialValue. If the same value is determined to be illegal, therefore, it is not always "null". I think the name of this control is called "illegal Verification" as well. In addition, RequiredFieldValidate has several important attributes (if the following controls have these attributes, they are used in the same way): Conclusion 2: l ErrorMessage: error message (used to display information displayed when verification fails. If Text is set, this attribute will be replaced by Text ). L Text: message displayed when verification fails (this value is displayed when verification fails; if this value is blank, the ErrorMessage value is displayed ). L Display: Display Mode (None-error message is not displayed on the control, Static-error message is displayed on the control, hidden after verification, but placeholder, dynamic-displays error information at the control, which is hidden after verification and does not occupy space. It is generally used when a control requires several verification bindings ). 2. CompareValidator (comparison Validation Control) This control specifically compares two values for equality. Conclusion 3: l ControlToCompare: ID of the control to be compared. L ControlToValidate: ID of the control to be compared. L ValueToCompare: the value to be compared. L Operator: The comparison symbol. When this condition is not met, an exception event is triggered (Equal-Equal, GreatThan-greater than, greatgatethan-greater than or Equal to, LessThan-less than, and LessEqualThan-less than or Equal ). [Note: this control cannot verify null values, so it is generally used with RequiredFieldValidator. You can select either ValueToCompare or ControlToCompare.] 3. RegularExpressionValidator (format verification) this control verifies whether the bound ID matches the regular expression. Conclusion 4: l ValidationExpression: The validation rule (regular expression ). L ControlToCompare: the ID of the control to be compared. [Note: this control cannot verify null values, so it is generally used with RequiredFieldValidator.] 4. RangeValidator (range verification) This control specifically verifies whether the bound ID value is within a certain range. Conclusion 5: l ControlToCompare: the ID of the control to be compared. L MaximunValue: maximum value. L MinimunValue: minimum value. [Note: this control cannot verify null values, so it is generally used with RequiredFieldValidator] 5. CustomValidator (custom verification) this control is used to enable custom verification to trigger rule implementation verification (for example, to verify whether a verification code matches the input, Microsoft does not provide such a control, assuming that the verification code is dynamically generated, and put it in the Session, the Session name Code ). Conclusion 6: l ControlToCompare: ID of the control to be compared. In this case, you should trigger the following events and write code verification (example): protected void CustomValidator1_ServerValidate (object source, ServerValidateEventArgs args) {string Code = Session ["code"]. toString (); args. isValid = (args. value = code);} l args. isvalid: verify whether it is valid (required ). L args. Value: the Value of the bound control (which must be compared with another Value ). [Note: this control must set ValidateEmptyText to True to verify the null value]

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.