Select and verify the form input line in ASP. NET

Source: Internet
Author: User

In ASP. NET, there are a series of validation controls that can easily verify whether the data entered by users is legal. Although these verification controls are powerful and easy to use, they have one drawback: when using them, when submitting a webpage, user input on the entire web page must be verified. In the verification control, there is no direct method to verify the input of some parts of the page. This article describes how to use asp.net to verify the control and javascript features to verify the input of only some parts of the page.
Why do I only need to verify the input of some parts of the page? For example, in some applications, sometimes for the convenience of user input, it is possible that in the same page, there are multiple forms that require users to enter and submit data (this is common in some background management systems of information systems ). For example, if you enter the quantity of each incoming goods and submit an operation, you only need to verify the submitted data, while other forms on the page, for example, because the user does not fill in the data for each shipment, it does not need to be verified, which also improves the efficiency of the application.
Next, let's take a look at how to selectively verify the form input. First, we will have a comprehensive understanding of some attributes and usage of the input verification control in asp.net.
First, we will introduce the causesvalidation attribute. If you do not want to verify the event submitted by a button, you only need to set the causesvalidation attribute to false. For example, if you have a "cancel" button, you can set it as follows:
<Asp: button id = "canonical Cancel" runat = "server" Text = "Cancel" CausesValidation = "False"> </asp: button>
Another method is:
Optional cancel. causesvalidation = false;
In this way, once the causesvalidation attribute is set to false, both client verification and server verification will not work.
If you want to selectively verify some parts of the page, you need to use some methods of the verification control and javascrpt. The following list lists some methods and attributes of the verification control:
Name
Description
Page_IsValid
Checks whether all inputs on the page are valid and returns a Boolean value.
Page_Validators
An array formed by all verification controls on the current page

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.