ASP. NET-how to: Verify the required ASP. NET Server controls

Source: Internet
Author: User

By adding Requiredfieldvalidator Control and link it to the required control, you can specify a user in ASP. NET Information must be provided in specific controls on the webpage. For example, you can specify that you must enter the "name" text box before submitting the registration form.

If the verification is performed on the client, you can leave the required fields blank (or retain the default values) when using this page, but you must provide non-default values before submitting the page. However, after you enter a value in a field, you cannot clear the field (or restore it to the default value ). If this field is cleared, the user will immediately see the error message when leaving this field. In server-side verification, no check is performed before the page is submitted. Therefore, the user will only see the error message after the page is submitted.

Note: Verification of required items is often used in conjunction with other types of verification. You can use multiple verification controls for a user input field as needed.

1 , requiredfieldvalidator Add the control to the page and set the following attributes:

attribute

description

controltovalidate

id .

errormessage , text , display

Some attributes are used to specify the text content and position of errors displayed when the user skips the control.

 

2 In ASP. NET WebpageCodeTo check validity. The following example demonstrates Textbox Server Control . Aspx File.

<Asp: textbox id = "txtlastname" runat = "server"> </ASP: textbox>

<Asp: requiredfieldvalidator id = "requiredfieldvalidator1" runat = "server"

Controltovalidate = "txtlastname"

Errormessage = "last name is a required field ."

Forecolor = "red">

</ASP: requiredfieldvalidator>

 

 

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.