Small Discoveries About how to prevent ASP. NET button controls from submitting pages

Source: Internet
Author: User

When using the ASP. NET button control, you often need to verify the client before submitting the page. If it fails, the page is not submitted.

Previously, we used the following method to do this:

< Script Language = Javascript event = Onclick For = Mybtn >

If (Is the Verification Successful ?)

Return   True // Allow Page Submission

Else

Return   False // Blocked Page Submission

</ Script >

 

However, this method has many restrictions, and sometimes it is not convenient to know the button ID. Therefore, you can also find the following method (ASP. NET 2.0)

<Asp: button... onclientclick = "Return myvalidation ()"/> (forgot whether ASP. NET 1.1 has the onclientclick attribute)

The myvalidation function continues to submit the page if true is returned. If false is returned, the page is not submitted.

In fact, the formal approach should be to use event. returnvalue = false to stop the submission, for example:

< Script Language = Javascript >
Function Beforesubmit ()
{
// If verification fails
Event. returnvalue =   False
}
</ Script >
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.