Powerful ASP. NET Control---validation controls

Source: Internet
Author: User

After studying the beef brisket, the ASP Learning, all of the knowledge, there is a sense of déjà vu, " Oh, this, in the Beef Brisket press release system. " , but at that time, use is also vaguely, say the use of the validation control, beef brisket in the code error, password, user name errors are used to verify the control, but at that time, just vaguely followed with, now there is a clear cloud to see the feeling of the moon.

    1. VS The left-hand toolbox provides us with a powerful set of validation controls

    1. From top to bottom, compare controls, user-defined validation controls, scope validation controls, regular expression controls, validation controls are empty, validation rollup controls (a summary of validation information)
      1. To compare the use of controls:

    1. to use the user-defined validation control, double-click the " user already exists " control, enter the background code authoring phase:

       protected void CustomValidator1_ServerValidate (Object Source,servervalidateeventargs args)        {           string UserName = args. Value;           SqlConnection con = new SqlConnection ("Server= Liu Ying-pc;database=login;uid=sa; pwd=123456; ");           Con. Open ();           SqlCommand cmd=new SqlCommand ("SELECT count (*) from login whereusername= '" +username+ "'", con);            Intcount=convert.toint32 (cmd. ExecuteScalar ());           if (Count > 0)            {               args. Isvalid=false;            }            else            {               args. IsValid = true;            }           Con. Close ();        }


    1. Use of scope validation controls

    1. Use of regular expression controls

    1. cannot be an empty control using the
    1. The validation rollup control collection is the errormessage property.
    1. CompareValidator controls,

Well , the function of the validation control is very powerful! than before we output MessageBox Prompt user input information is wrong, simple and beautiful!

Powerful ASP. NET Control---validation controls

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.