System.Web.UI.WebControls Namespace CustomValidator Class
Occurs when validation is performed on the server.
[ VB ]
Public Event ServerValidate As ServerValidateEventHandler
[ C# ]
public event ServerValidateEventHandler ServerValidate;
[ C++ ]
public: __event ServerValidateEventHandler* ServerValidate;
In [ JScript ], you can handle the events defined by a class, but you cannot define your own.
The method assigned to handle the event is passed a string containing the text to validate.
The ServerValidate event is raised whenever validation is performed on the server. This event is used to provide a custom validation routine for an input control, such as a TextBox control.
The following example demonstrates how to declaratively specify a handler for a server-side CustomValidator control.
<asp:customvalidator id = "CustomValidator1" runat = "server"
controltovalidate = "myTextBox"
clientvalidationfunction = "ClientValidate"
onServerValidate = "ServerValidate"
display = "Static" />
The below shows the code for the custom validation routine, which simply validates the value of a TextBox control for an even number, and then displays the result of the validation.
bool ServerValidate ( Object src, string value ) {
// even number?
try {
int num=Int32.FromString ( value );
if ( num%2 == 0 ) return true;
}
catch ( Exception ) {}
return false;
}
Show me
CustomValidator Members Validating with a Custom Function