Thursday, January 3, 2013

How to use CustomValidator with Server Side Validation Method

Below is the custom validator.

<asp:CustomValidator id="CustomValidator1" runat="server" OnServerValidate="RevisionValidate" ControlToValidate="TextBoxRevisionOrder" ErrorMessage="Invalid RevOrder Format"> </asp:CustomValidator> 

OnServerValidate - Server side method name.
ControlToValidate - Text box id to validate.

protected void RevisionValidate(object source, ServerValidateEventArgs args) 
    //Validation Code goes here

On a button click event i need to fire the validation.
Inside the button click event first you need to add the below code.

if(Page.IsValid) {


Any other code that you need to execute on the button click event, add inside the above "if" condition.

No comments:
Write comments
Recommended Posts × +