Verify the use of controls in Web Development

Source: Internet
Author: User

In web development, many input items on the Web page must be verified before being submitted to the server. ASP. NET provides a series of verification controls, allowing you to easily verify the content of the text box (more in-depth verification can be achieved through regular expressions, and will be introduced later ).

Requiredfieldvalidator Control
This control is used to change an input item to a required field, meaning that the input item cannot be blank. It has an attribute used to bind the verified control: controltovalidate, for example, <asp: requriedfieldvalidator id = "rfvname" runat = "server" Controltovalidate = "txtname" Errormessage = "Enter name" text = "*"> <asp: requriedfieldvalidator/> Code Use the requriedfieldvalidator control to verify whether the txtname of the text box is empty. Rangevalidator Control This control is used to verify whether the data of the input item is within the specified range. It is invalid to check the data of this range. It is also bound to the verified control through the controltovalidate attribute, the minimumvalue and maxmumvalue attributes are used to determine the minimum and maximum values of a specified range. For example, <asp: rangevalidator id = "rvmonth" Controltovalidate = "txtmonth" Minimumvalue = "1" Maxmumvalue = "12" Errormessage = "the month must be between 1 and 12" type = integer
Runat = "server"/> This code is used to verify whether the input accepted by the txtmonth control is between 1 and 12 Validationsummery Control
This control is used for verification on the summary page. Program The error message is displayed on the webpage or in a prompt box. For example, add the following code below the above Code about rangevalidator: <asp: validationsummery id = "vsmonth" runat = "server"
Showmessagebox = "true" Showsummery = "false" /> If you enter "13" in the txtmonth text box, a prompt box is displayed, showing "the month must be between 1 and 12 ". Properties Showmessagebox andShowsummery is used to determine whether the error summary is displayed in the prompt box or on the webpage. I am a beginner in B/S development. I hope this article Article It can be helpful for beginners to verify 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.