Search code examples
c#asp.netvalidationcustomvalidatorasp.net-validators

How to get the 'controlToValidate' property on ClientValidationFunction?


Lets say I have this code.

<asp:TextBox ID="TextBox1" runat="server" />

<asp:CustomValidator ID="CustomValidator1" runat="server"
    ClientValidationFunction="ValidationFunction1"
    ControlToValidate="TextBox1"
    Display="Dynamic" />

And a validationFunction:

function ValidationFunction1(sender, args)
{
}

And i would like to know if, inside the function I could get the Control to validate something like:

var v = sender.ControlToValidate;

Solution

  • Actually sender.controltovalidate gives the ClientID of the control. So this seems like a solution.

    function ValidationFunction1(sender, args){
        var v = document.getElementById(sender.controltovalidate);
    }
    

    I tried and it worked for me. Please notify if it works.