Some experiences on the association of the custom client verification script with the server control at the same time

Source: Internet
Author: User

. NET provides us with a lot of verification controls, to some extent reducedProgramDevelopers work on development, but sometimes we often need to customize some of our own verification processes, rather than using the verification control provided in. net. Generally, verification is divided into client-side and server-side verification. The verification mentioned here refers to client-side verification.

The most common practice is to write a javsscript script by yourself, and return true or false based on whether the verification succeeds. Then, the Javascript script function is called when the server control is triggered by using controlid. Attribute ["Event"] = "javascript: functionname. But there is a problem when writing this, that is, when there are other pages on this page.. net, once the User-Defined script function is used to verify the control, the server will not verify the control.

That is, when controlid. if the attribute ["Event"] value is set to true, the compiler considers that it has passed all the verification, including..CodeSent to the server for execution. However, the. NET verification control has not been executed yet. However, as long as the code is slightly changed, after the custom verification is executed, the. NET verification control can still be executed.

Function validate ()
{
If (...) // if it passes Verification
{Return true ;}
Else
{Return false ;}
}
Then we add
Controlid. Attribute ["Event"] = "javascript: If (! Functionname () {return false ;}: "; if the custom verification fails, false is returned, and the control is not submitted to the server for execution. Otherwise, then proceed with the verification of other spaces on the page.

Sometimes reverse thinking is often ineffective.

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.