Requiredfieldvalidator for ASP. NET verification controls

Source: Internet
Author: User

I believe that people with experience in ASP. NET programming will not be unfamiliar with requiredfieldvalidator. This control is used to disable the input of specified content (that is, attributeInitialvalue. The default value of this attribute is an empty string. It is often used to verify whether the content entered by the user is null.). In addition, spaces at both ends of the input content are automatically removed before verification.


Let's take a look.Common attributes of requiredfieldvalidator:

Attribute

Description

Backcolor

Background Color

Controltovalidate

ID of the verified Control

display

display of error messages in the control.

· none-the verification message is never displayed inline.

· static-allocate space in the page layout for displaying verification messages.

· dynamic-If verification fails, the space used to display verification messages is dynamically added to the page.

Enableclientscript

Boolean value that specifies whether to enable client verification. True indicates enabled, and false indicates disabled.

Enabled

Boolean value that specifies whether to enable the verification control.True indicates enabled, and false indicates disabled.

Errormessage

Text displayed in the validationsummary control when verification fails.

Note: If the text property is not set, the text is displayed in the verification control.

Forecolor

The foreground color of the widget. That is, the font color of the error message.

ID

The unique ID of the control.

Initialvalue

Specifies the initial value (start value) of the input control ). The default value is a null string.It indicates youNoThe value entered by the user in the input control.

Isvalid

Boolean value indicating whether the associated input control has passed verification.True indicates pass, and false indicates fail.

Runat

Specifies that the control is a server control. Must be set to "server ".

Text

Message displayed when verification fails.

After reading the common attributes of requiredfieldvalidator, let's make a small instance to practice it.

 

 <%  @ Page Language  = "  C #  "  Autoeventwireup  =  "  True  "  Codebehind  =  "  The username cannot be empty. aspx. CS "  Inherits  =  "  Webapplication1. the user name cannot be blank. 1  "   %>  <!  Doctype html  >  <  Html  Xmlns = "Http://www.w3.org/1999/xhtml"  >  <  Head  ID  = "Head1"  Runat  = "Server"  >  <  Meta  HTTP-equiv  = "Content-Type"  Content  = "Text/html; charsets = UTF-8"  />     <  Title  > The user name cannot be blank. </  Title  >  </  Head  >  <  Body  >      <  Form  ID  = "Form1"  Runat = "Server"  >            <  ASP: Label  ID  = "Lbusername"  Runat  = "Server"  Text  = "User name :"  > </  ASP: Label  >          <%  -- User name entered by the recipient  --  %>          <  ASP: textbox  ID  = "Txtusername"  Runat  = "Server"  > </  ASP: textbox  >         <%  -- Verify that the user name is empty  --  %>          <  ASP: requiredfieldvalidator  ID  = "Requiredfieldvalidator1"  Runat  = "Server"  Forecolor  = "Red"  Text  = "User name cannot be blank"  Controltovalidate = "Txtusername"    > </  ASP: requiredfieldvalidator  >                  <  BR  />          <  BR  />                  <%  --  Submit information for the server to verify whether the input meets the requirements  -- %>          <  ASP: button  ID  = "Btnsubmit"  Runat  = "Server"  Text  = "Submit"    />             </  Form  >  </  Body  >  </ Html  > 

 

 

 

If you do not enter any content or enter only spaces, click the right side of the submit text box to display several very eye-catching Red prompts, "user name cannot be blank.
 

Here we use the default verification value of the control, that is, it cannot be blank. Of course, you can also set other content that is not allowed to be input as needed.Initialvalue = "the input value is not allowed.


Requiredfieldvalidator is easy to use. You only need to know its common attributes to meet our basic needs. Although it is simple, it is often used. So let's sort it out.

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.