开发者

How to set 'ClientValidationFunction' property in <asp:CustomValidator>

I need to use asp:CustomValidator for a tool. The problem am facing is that on calling a function using the property 'ClientValidationFunction', the function is getting called but even a single line of javascript is not getting executed. I placed a simple alert() inside the function. Its also 开发者_如何学Cnot executed.

Can any one please suggest a solution for this? Thanks in advance


Ensure there are no other JavaScript errors on the page. Also, it should work if you add either ControlToValidate property or the ValidationGroup for the validator.


See the CustomValidator below:

     <asp:CustomValidator ID="valCustmCheckDate" runat="server" ErrorMessage="The date   difference should not be greater than 100 days" ForeColor="Red" ValidationGroup="LoginUserAdd" ClientValidationFunction="CompareStartAndEndDate"></asp:CustomValidator>  

It calls the following Javascript function below:

   function CompareStartAndEndDate(sender,args) {

    var txtBox = document.getElementById('<%=txtBoxID.ClientID %>');

    var validation=//do your validation of txtBox.value here;

   if (!validation) {

        args.IsValid = false; //this will display your validation error msg and stops at clent side itself
    }
    else {
         args.IsValid = true;// this will allow server side run
    }

Hope this helps.. }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜