Customvalidator is a user-defined verification control that responds to user-defined verification. The JS client functions can be written in the background.CodeServer verification function in.
The following are common attributes of customvalidator:
Attribute |
Description |
Backcolor |
Background color. |
| clientvalidationfunction |
specifies the name of the custom client script function used for verification. note: the script must be written in a language supported by the browser, for example, VBSCRIPT or JScript when VBScript is used, the function must be in the form: sub functionname (source, arguments) If JScript is used, the function must be in the form: function functionname (source, arguments) |
| controltovalidate |
ID of the input control to be verified. |
| display |
verify the display behavior of error messages in the control. valid values: · none-the verification message is not displayed inline. · static-allocate space in the page layout for displaying verification messages. · dynamic-If verification fails, dynamically Add the space used to display verification messages to the page. |
Enableclientscript |
Boolean value indicating whether client verification is enabled. |
Enabled |
Boolean value indicating whether to enable the verification control. |
Errormessage |
The text of the error message displayed in the validationsummary control when verification fails. Note: If the errormessage attribute is set but the text attribute is not set, the value of the errormessage attribute is also displayed in the verification control. |
Forecolor |
The foreground color of the widget. |
ID |
The unique ID of the control. |
Isvalid |
Boolean value indicating whether the associated input control has passed verification. |
Onservervalidate |
Specifies the name of the script function to be executed on the server. |
Runat |
Specifies that the control is a server control. Must be set to "server ". |
Text |
Text displayed when verification fails. |
Learn how to use customvalidator
<% @ Page Language = " C # " Autoeventwireup = " True " Inherits = " Default2 " Codebehind = " Default2.aspx. CS " %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < Html Xmlns = "Http://www.w3.org/1999/xhtml" > < Head Runat = "Server" > < Title > Custom Controls</ Title > < Script Type = "Text/JavaScript" Language = "JavaScript" > Function Clientv (S, e) {e. isvalid = (E. Value = " Client " );} </ Script > </ Head > < Body > < Form ID = "Form1" Runat = "Server" > < Div > Client Verification < ASP: textbox ID = "Txtclient" Runat = "Server" > </ ASP: textbox > < ASP: customvalidator ID = "Customvalidator2" Runat = "Server" Controltovalidate = "Txtclient" Errormessage = "Client Verification Failed" Clientvalidationfunction = "Clientv" Forecolor = "Red" > </ ASP: customvalidator > < BR /> Server Verification < ASP: textbox ID = "Txtserver" Runat = "Server" > </ ASP: textbox > < ASP: customvalidator ID = "Customvalidator1" Runat = "Server" Controltovalidate = "Txtserver" Errormessage = "Server Verification Failed" Onservervalidate = "Server_servervalidate" Forecolor = "Red" > </ ASP: customvalidator > </ Div > < ASP: button ID = "Button1" Runat = "Server" Onclick = "Button#click" Text = "Submit" /> </ Form > </ Body > </ Html >
Server verification function written in CS File
//Server Verification MethodProtected VoidServer_servervalidate (ObjectSource, servervalidateeventargs ARGs) {args. isvalid= (ARGs. value ="Server");}
The client prompts that the verification failed and no information is submitted at this time, so the server verification will not be executed.
The client passes the verification and the server fails the verification.
One thing to note is that customvalidator does not verify the content with null values or all spaces. This can be used with other controls mentioned earlier.