A small conflict between ASP. NET validation controls and client scripts

Source: Internet
Author: User

 

A simple ASP. NET page, add a submit button (ASP: button) in an email input box. All you need to do is verify that the input content meets the email requirements through requiredfieldvalidator and regularexpressionvalidator, click the submit button to perform the submit operation.

The problem here is that, if this is the case, when we click the submit button, if the entered content does not meet the requirements, the control will directly display the error message and the page will not be refreshed again, in fact, the control generates a series of scripts to make judgments, which is the same as writing JavaScript on our own. If we add the onclientclick event to the button and add some scripts by ourselves, the verification control will still take effect, however, whether to stop button submission depends on whether the content returned by the onclientclick event is false or true. At the same time, the page will be PostBack and execute the backgroundCodeIn fact, the so-called verification control also binds its own script to the button and controls its submission time. If we write the client script by ourselves, it is necessary to take full responsibility for determining whether to submit, rather than placing all the responsibility on the server-side 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.