How to get the 'controlToValidate' property on ClientValidationFunction?

DJPB picture DJPB · Sep 3, 2010 · Viewed 18.4k times · Source

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;

Answer

Musa Hafalır picture Musa Hafalır · Sep 3, 2010

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.