Friday, February 11, 2011

Custom Validator

There are two ways to use the custom validator, the client side validation and the server side. I think the server side keeps thing simple, I was using one on my form, and I intended to use it on the client side i.e. call a function in javascript with two parameters like

function validate(sender args)
      //validation code
      args.isValid=true; //or false
the validator itself has the OnClientValidate=validate()

I was saying the server validation does not slow thing its almost equal in time limit to the client validation.
The server side validation is similar have a validate function that returns isValid:

protected void validate(sender as Object, args as ServerValidateEventArgs)
//validation code
args.isValid = true // or false

I did put the validation into an update panel, like

<asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Error" ClientValidationFunction></asp:CustomValidator>
            <asp:CustomValidator ID="CustomValidator2" runat="server" ErrorMessage="Error" OnServerValidate></asp:CustomValidator>

Maybe that did something to the updation of the control 

No comments:

Post a Comment