1
votes

I've created a custom control in a class project(DLL) and am using it in a page where I have the standard ASP.net required field validator control to ensure some property of the custom control is filled by the user.

For some reason, validation only happens after postback. I need the validation to happen on the client-side before postback i.e in a similar manner to the way a standard text box is validated by the ASP.net validator controls.

Please help.

3
have you tried some thing... - Bhupendra Shukla
tried what? Yes I tried some ideas from the internet and none of them has helped me in this specific scenario - Yosief Kesete
have You used any Code, if u could please give the code here - Ashish Babu

3 Answers

2
votes

you can use ClientValidationFunction property of CustomValidator.

  <asp:CustomValidator id="CustomValidator1"
       ControlToValidate="Text1"
       ClientValidationFunction="ClientValidate"
       OnServerValidate="ServerValidation"
       Display="Static"
       ErrorMessage="Not an even number!"          
       runat="server"/>




<script language="javascript"> 
   function ClientValidate(source, arguments)
   {
        if (arguments.Value % 2 == 0 ){
            arguments.IsValid = true;
        } else {
            arguments.IsValid = false;
        }
   }
</script>
1
votes

I guess u might be wanting to fire the validation on some events like Button etc. Then check, have you made the CausesValidation Property of the Button to be true. for example

<asp:Button ID="Submit" runat="server" Text="Submit" CausesValidation="True" ClientIDMode="Static"/>
0
votes

You need to apply ValidationProperty attribute to your user control, its value pointing to the name of the property which will be validated by the validation control

Check this link http://www.matthewedmondson.info/2010/01/validatation-for-custom-user-controls.html