ASP.NET is immediately going to tutorial 6

xiaoxiao2021-03-06  24

Form Verification Server Control Verification This section includes a server control for verification of a server control for verification, and displays prompt information to check the incorrect input form. Add the verification control to the design loop table, just like adding other server controls. Verify that there are different validation types, such as scope checks or patterns, add a RequiredFieldValidator control to ensure that users cannot skip a field that requires input content. You can combine a number of verification controls for an input control. For example, you may ask a certain field can't be empty, and you must enter a range of values. Verify that the control and the limited subset of the server control work together. That is, for different controls, you may need to verify the values ​​of different properties. The following table lists the properties of the control input controls that may be verified authentication properties HtmlInputText ValueHtmlTextArea ValueHtmlSelect ValueHtmlInputFile ValueTextBox TextListBox SelectedItem.ValueDropDownList SelectedItem.ValueRadioButtonList SelectedItem.Value validation control is the simplest form of authentication is required input field. Regardless of whether the user entered any value in the field, it is verified. If all fields in the page are verified, the page is also validated (Page is Valid). The following example illustrates the use of the RequiredFieldValidator verification control. C # Validator1.aspx [Run] | [Source Code] Specific verification requires different verification controls, such as range checks or patterns. The following table lists all verification controls: Control Name Description RequiredFieldValidator guarantees that users cannot ignore input. CompareValidator compares the user's input and constant (or the property value of another control) RangevaliDator to check the user's input within a specific maximum and minimum range. You can verify the input range with a pair of numbers, characters, or dates. The range boundaries can use expressions that can get constants. RegularExpressionValidator checks the user input to match the pattern defined by a regular expression. This verification allows you to check the foreseeable character sequences, such as social insurance numbers, email addresses, telephone numbers, postal codes, and more. CustomValidator uses your own verification logic to check the user's input. This verification allows you to check the values ​​obtained at runtime. ValidationSummary Abstract Display All Verification Error Messages Client Verification of Pages On the page Verify that verification is always performed on the server side. However, if the user is working with a browser that supports DHTML, verifying the client script can also be verified using the client script. By confirming by the client, when the form is submitted to the server, any detection of the client can be found. When any of the verification, the form is discovered, the form submitted to the server will be canceled, and the TEXT property of the verification interval is displayed. This allows the user to correct the input error before the form is submitted to the server. When the field contains the wrong field, this field will be re-authenticated. This gives users a rich, interactive verification process. Note: The Web Forms page is always verified on the server side, even if it is verified that it has been executed on the client. This helps prevent the prevention of replacement and booking a transaction through verification. The client is allowed to verify by default. If the client condition allows, the high version browser verification mode will be executed automatically.

To prohibit client authentication, set the clientTarget property to "DOWNLVEL" ("UPLEVEL" Forced Client Verification) C # Validator2.aspx [Run] | [Source Code] Display Verification Error Information When the user's input starts processing (for example,, When the form has been submitted), the Web Forms page frame passes the user's input to the associated verification control. Verify that the control test user's input and set the properties to log your input by verifying test. After all the verification controls are running, set the isvalID property of the page. If any of the verification controls displays a failed verification, the verification of the entire page is also invalid. If the validation control is monitored, the Validationsummary control on the page is displayed on the page displays an error message on the page. The value of the ValidationsumMary control shows the error prompt is the isvalid of the page is equal to FALSE. (That is, any verification control is not passed, it will activate the validationsummary, which can monitor the verification error of each verification control and display all errors all. The following example demonstrates how the ValidationsumMary control is incorrectly prompted. C # Validator3.aspx [Run] | [Source Code] Using the Compare Verification Control CompareValidatorCompareValidator server authentication control used to compare the value of the two controls. It uses three key properties to perform its verification. ControlTovAlidate and ControlToCompare contain values ​​to be compared, Operator defines the comparison type to be performed -, for example, or not equal to, etc.. COMPAREVALIDATOR performs verification by evaluating expression, like this: (ControlToValidate ControlToCompare) If the value of the expression is true, the verification result is passed. The following example illustrates how to use the CompareValidator control C # Validator4.aspx [Run] | [Source Code] Using the Range Verification Control RangevaliDatorRangeValidator server control test input value within a given range. RangeValidator uses three critical properties to perform verification. ControlTovAlidate contains validated objects, MinimumValue, and MaximumValue define the minimum and maximum values ​​of the valid range. The following example shows how to use the RangeValidator control. C # Validator5.aspx [Run] | [Source Code] Using Regular Expression Verification Control RegulaRexpressionValidatorRegulaRexpressionValidator Server controls to check if the user enters the pattern matching the regular expression definition. This control allows you to check the foreseeable string series, such as social security numbers, email addresses, phone numbers, and postal codes. RegularExpressionValidator uses two critical properties to perform verification. ControlTovAlidate contains control objects to be verified, the ValidationExpression contains the regular expression that matches. The original textbook is relatively small, here I will add: Regular expression is a powerful string definition rule, such as "*" and "?" He earlier in UNIX. In ASP.NET, his format is [acceptable characters] {range}. For example, [AZ] {3, 7} indicates at least three characters, with a maximum of 7 characters, wherein the characters can only range 'a' ~ 'Z', such as "KrPam" is legal, and "" 12FE3 "or" 5W "is illegal.

转载请注明原文地址:https://www.9cbs.com/read-40236.html

New Post(0)