asp.net.ph

CustomValidator.ServerValidate Event

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.

Event Data

The method assigned to handle the event is passed a string containing the text to validate.

Remarks

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.

Example

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 

See Also

CustomValidator Members   Validating with a Custom Function Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph