The "ASP. NET" validation control

Source: Internet
Author: User

Learn about the following six validation controls by looking at ASP. Do you know what each control does without Chinese comments? Down here.

Introduction some of these controls.


First, RequiredFieldValidator (Limit empty fields)

Used to make a specific input control a required item, and if empty, a hint is given.

Common Properties:

ControlToValidate: The control to validate

ErrorMessage: Information for the prompt.

Display: static and Dynamic Dynamics

Static statics:


Dynamic Dynamics



Second, CompareValidator (compare controls)

Used to compare the value entered by the user into the input control with the value or constant value entered into the other input control

More.

Common properties In addition to the above control property settings are:

Operator: Gets or sets the comparison operation to perform.

ValueToCompare: Gets or sets a constant value to be entered with the input controlled by the user into the validated in pieces the value to compare.


if it's a date type, put operator change it and you can change it to a date.

Third, RangeValidator (check the specified range)

Check that the value of the input control is within the specified range of the setting, take the date type as an example, exceed the prompt, and set the properties as follows:


Iv. RegularExpressionValidator (using an expression to check values)

The function of this control is to let us write according to certain rules, only need to select the corresponding expression in the ValidationExpression attribute list.

v. CustomValidator (custom validation)

To perform user-defined validation of the input control, you need to write the method for server-side validation, which is the following:

There are two parameters, the first one is the control that represents the validation, and the second represents the event data. The second parameter has two Properties: The IsValid is used to indicate that a validated control

is validated, the Value property represents the values.

<span style= "FONT-SIZE:18PX;" >   protected Voidcustomvalidator1_servervalidate (object source, ServerValidateEventArgs args)        {            String userName = args. Value;            SqlConnection con =db.createconnection ();            Con. Open ();            SqlCommand cmd = Newsqlcommand ("Select Count (*) from login whereusername= '" +username+ "'", con);            int Count =convert.toint32 (cmd). ExecuteScalar ());            if (Count > 0)            {                args. IsValid = false;            }            else            {                args. IsValid = true;            }            Con. Close ();        } </span>

Vi. ValidationSummary (verification rollup)

The error message that is displayed in the control is specified by the ErrorMessage property of each validation control. If the validation control is not set

ErrorMessage property, the error message is not displayed for that validation control.

Vii. Summary

The above summary of the control is learned in the video, comparative basis, the current understanding of it is this Some, feel more impressed by summing up

some. Many of the original verification is through the code to complete, after learning to find a control to solve, very cool.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The "ASP. NET" validation control

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.