Search code examples
javascriptasp.netcustomvalidator

referencing the source control in the CustomValidator control


Is it possible to get a reference to the textbox that the customvalidator is 'attached' to in javascript?

I want to place a red border around the texbox if it fails validation.


Solution

  • Your javascript validation function will have access to "sender" and "args" parameters. The control that is being validated may be accessed from the "sender" as follows.

    function doValidation(sender, args)
    {
        alert(sender.attributes["controltovalidate"].value);
    }