validation Controls:1, non-null validation RequiredFieldValidator properties: errormessage: Validation failed error message to display Forecolor: color of text Display: Displayed in the default static space, dynamic does not occupy space ControlToValidate: The control to validate Validaiongrou P: Validation Grouping2, contrast validation CompareValidator properties: errormessage: Validation failed error message display: How to display ControlToValidate: The control to validate ControlToCompare: The control to compare type: By what type compare Validaio Ngroup: Validation Grouping3, scope validation RangeValidator properties: errormessage: Validation failed error message displayed display: How to display the Co Ntroltovalidate: The control to validate Maximumvalu: The maximum value of the range Minimumvalu: The minimum value of the range type: by what class Type comparison validaiongroup: Validation grouping4, Regular expression validation RegularExpressionValidator properties: errormessage: Validation failed error message display: How to display ControlToValidate: The control to validate ValidationExpression: regular expression to validate Validaiongroup: validation grouping 5, Validation rollup control: ValidationSummary Properties: Validaiongroup: Verifying grouping ShowSummary: Displaying error summary information as a text summary ShowMessageBox: Displaying error summary information as a dialog box
ASPX code:
<%@ Page Language="C #"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_default" %><!DOCTYPE HTML><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Headrunat= "Server"><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"/> <title></title></Head><Body> <formID= "Form1"runat= "Server"> <Div> <Asp:labelID= "Label1"runat= "Server"Text= "User name:"></Asp:label> <Asp:textboxID= "Txtname"runat= "Server"></Asp:textbox> <Asp:requiredfieldvalidatorID= "RequiredFieldValidator1"runat= "Server"ControlToValidate= "Txtname"Display= "Dynamic"errormessage= "User name cannot be empty!" "ForeColor= "Red"ValidationGroup= "Zhuce"ViewStateMode= "Disabled"></Asp:requiredfieldvalidator> <BR/> <BR/> <Asp:labelID= "Label2"runat= "Server"Text= "Password:"></Asp:label> <Asp:textboxID= "Txtpwd1"runat= "Server"></Asp:textbox> <Asp:requiredfieldvalidatorID= "RequiredFieldValidator2"runat= "Server"ControlToValidate= "Txtpwd1"Display= "Dynamic"errormessage= "Password cannot be empty!" "ForeColor= "Red"ValidationGroup= "Zhuce"></Asp:requiredfieldvalidator> <BR/> <BR/> <Asp:labelID= "Label3"runat= "Server"Text= "Confirm Password:"></Asp:label> <Asp:textboxID= "Txtpwd2"runat= "Server"></Asp:textbox> <Asp:comparevalidatorID= "CompareValidator1"runat= "Server"ControlToCompare= "Txtpwd1"ControlToValidate= "Txtpwd2"Display= "Dynamic"errormessage= "Two times the password entered is inconsistent!" "ForeColor= "Red"ValidationGroup= "Zhuce"></Asp:comparevalidator> <BR/> <BR/> <Asp:labelID= "Label4"runat= "Server"Text= "Age:"></Asp:label> <Asp:textboxID= "Txtage"runat= "Server"></Asp:textbox> <Asp:rangevalidatorID= "RangeValidator1"runat= "Server"ControlToValidate= "Txtage"Display= "Dynamic"errormessage= "Age must be between 18-45 years old!" "ForeColor= "Red"MaximumValue= "$"MinimumValue= "+"Type= "Integer"ValidationGroup= "Zhuce"></Asp:rangevalidator> <BR/> <BR/> <Asp:labelID= "Label5"runat= "Server"Text= "ID Number:"></Asp:label> <Asp:textboxID= "txtID"runat= "Server"></Asp:textbox> <Asp:regularexpressionvalidatorID= "RegularExpressionValidator1"runat= "Server"ControlToValidate= "txtID"Display= "Dynamic"errormessage= "ID card number does not conform to the rules!" "ForeColor= "Red"ValidationExpression= "\d{17}[\d| X]|\D{15} "ValidationGroup= "Zhuce"></Asp:regularexpressionvalidator> <BR/> <BR/> <Asp:buttonID= "Button1"runat= "Server"OnClick= "Button1_Click"Text= "Register"ValidationGroup= "Zhuce" /> <asp:validationsummaryID= "ValidationSummary1"runat= "Server"ValidationGroup= "Zhuce" /> </Div> </form></Body></HTML>
Validation controls only need to modify properties in the control without writing background code
20151227:web: Validation Controls